Cod sursa(job #2009602)

Utilizator MaligMamaliga cu smantana Malig Data 10 august 2017 08:57:35
Problema Suma si numarul divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.54 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream in("ssnd.in");
ofstream out("ssnd.out");

#define ll long long
#define ull unsigned long long
#define pb push_back
const ll NMax = 1e12 + 5;
const int valMax = 1e6 + 5;
const int sqMax = 320;
const int mod = 9973;

int T,nrPrimes;
int primes[valMax];
bool notPrime[valMax];

ll pw(ll base,ll exp) {
    ll ans = 1;
    while (exp) {
        if (exp & 1) {
            ans = (ans * base) % mod;
        }
        base = (base * base) % mod;
        exp >>= 1;
    }

    return ans;
}

int main() {

    primes[++nrPrimes] = 2;
    for (int i=3;i <= valMax;i+=2) {
        if (notPrime[i]) {
            continue;
        }

        primes[++nrPrimes] = i;
        for (int j=3*i;j <= valMax;j += 2*i) {
            notPrime[j] = true;
        }
    }

    in>>T;
    while (T--) {
        ll N;
        in>>N;

        ll p,nrD = 1,top = 1,bot = 1;
        for (int i=1;(p = primes[i]) != 0 && p*p <= N;++i) {
            if (N%p != 0) {
                continue;
            }

            int d = 0;
            while (N%p == 0) {
                N /= p;
                ++d;
            }

            nrD *= d+1;
            top = (top * ((pw(p,d+1) - 1) + mod)) % mod;
            bot = (bot * (p - 1)) % mod;
        }
        if (N != 1) {
            nrD *= 2;
            top = (top * (N+1)) % mod;
        }

        out<<nrD%mod<<' '<<(top * pw(bot,mod-2)) % mod<<'\n';

    }

    in.close();out.close();
    return 0;
}