Cod sursa(job #2089875)

Utilizator MaligMamaliga cu smantana Malig Data 17 decembrie 2017 12:23:00
Problema Suma si numarul divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.88 kb
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>

#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");

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
const int NMax = 5e5 + 5;
const int valMax = 1e6 + 5;
const int mod = 9973;

ll nrPrimes;
ll 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() {
    ll T,N;

    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 <= 20;++i) {
        cout<<primes[i]<<'\n';
    }
    //*/

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

        ll nrDiv = 1,sumBot = 1,sumTop = 1,p;
        for (ll 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;
            sumTop = (sumTop * ((pw(p,d+1) - 1 + mod) % mod)) % mod;
            sumBot = (sumBot * ((p - 1 + mod) % mod)) % mod;
        }
        if (N != 1) {
            nrDiv *= 2;
            sumTop = (sumTop * (N+1)) % mod;
        }

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

    return 0;
}