Cod sursa(job #2126306)

Utilizator MaligMamaliga cu smantana Malig Data 9 februarie 2018 15:03:14
Problema Suma si numarul divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.84 kb
#include <bits/stdc++.h>

#if 1
#define pv(x) cout<<#x<<" = "<<x<<"; ";cout.flush()
#define pn cout<<endl
#else
#define pv(x)
#define pn
#endif

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

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
#define pb push_back
#define mp make_pair
const int NMax = 1e12 + 5;
const int valMax = 1e6 + 5;
const int inf = 1e9 + 5;
const int mod = 9973;
using zint = int;

ll T,N,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 (ll i = 3;i <= valMax;i += 2) {
        if (notPrime[i]) {
            continue;
        }

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

    /*
    for (int i = 1;i <= 23;++i) {
        cout<<primes[i]<<' ';
    }
    //*/

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

        ll nrDiv = 1, nrTop = 1, nrBot = 1, p;
        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;
            }

            nrDiv *= d+1;
            nrTop = (nrTop * (pw(p,d+1) - 1 + mod)) % mod;
            nrBot = (nrBot * (p - 1)) % mod;
        }
        if (N != 1) {
            nrDiv *= 2;
            nrTop = (nrTop * (N + 1)) % mod;
        }

        out<<nrDiv<<' '<<(nrTop * pw(nrBot,mod-2) % mod)<<'\n';
    }

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