Cod sursa(job #2062904)

Utilizator MaligMamaliga cu smantana Malig Data 10 noiembrie 2017 22:07:14
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.88 kb
#include <iostream>
#include <fstream>
#include <set>
#include <cstring>
#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");

using ll = long long;
using ull = unsigned long long;
using ui = 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;
ll primes[valMax];
bool notPrime[valMax];

ll pw(ll,ll);

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

        //pv(i);

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


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

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

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

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

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;
}