Cod sursa(job #1414808)

Utilizator irimiecIrimie Catalin irimiec Data 3 aprilie 2015 01:47:38
Problema Suma si numarul divizorilor Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 2.06 kb
#include <bits/stdc++.h>

using namespace std;

#define     mp              make_pair
#define     fs              first
#define     sc              second
#define     pob             pop_back
#define     pub             push_back
#define     eps             1E-7
#define     sz(a)           a.size()
#define     count_one       __builtin_popcount;
#define     count_onell     __builtin_popcountll;
#define     fastIO          ios_base::sync_with_stdio(false)
#define     PI              (acos(-1.0))
#define     linf            (1LL<<62)//>4e18
#define     inf             (0x7f7f7f7f)//>2e9

#ifndef ONLINE_JUDGE
ifstream fin("ssnd.in");
ofstream fout("ssnd.out");
#endif

typedef long long ll;

const int MAXN = 1E+6 + 10;
const int MOD = 9973;
int sieve[MAXN/2+1];
int primes[MAXN/8];
int k;

void eras() {
    primes[++k] = 2;
    for(int i = 1; (i << 1) + 1 <= MAXN; ++i)
        if(!sieve[i]) {
            primes[++k] = 2 * i + 1;
            for(int j = i + i + i + 1; (j << 1) + 1 <= MAXN; j += (1 << i) + 1)
                sieve[j] = true;
        }
}

int lgput(int base, int exp) {
    int sol = 1;
    base %= MOD;
    for(int i = 0; (1 << i) <= exp; ++i) {
        if(((1 << i) & exp) > 0)
            sol = (sol * base) % MOD;
        base = (base * base) % MOD;
    }

    return sol;
}

void read() {
    int T, p;
    int sum, nd;
    ll n;

    fin >> T;
    while(T--) {
        fin >> n;
        sum = nd = 1;
        for(int i = 1; i <= k && 1LL * primes[i] * primes[i] <= n; ++i) {
            if(n % primes[i]) continue;
            p = 0;
            while(n % primes[i] == 0)
                n /= primes[i], ++p;

            int p1 = lgput(primes[i], p + 1) - 1;
            int p2 = lgput(primes[i]-1, MOD - 2);

            sum = (((sum * p1) % MOD) * p2) % MOD;
            nd *= (p + 1);

        }

        if(n > 1)
            nd *= 2,
            sum = (1LL * sum * (n + 1) % MOD);
        fout << nd << " " << sum << "\n";
    }
}

int main() {
    eras();
	read();

    return 0;
}