Cod sursa(job #2495171)

Utilizator radugheoRadu Mihai Gheorghe radugheo Data 18 noiembrie 2019 22:24:41
Problema Suma si numarul divizorilor Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.66 kb
#include <bits/stdc++.h>
#define MOD 9973

using namespace std;

ifstream fin  ("ssnd.in");
ofstream fout ("ssnd.out");

long long t, n, i, m, a, b;
long long p[100005], f[1000005];

long long lgput (long long a, long long b){
    if (b == 0){
        return 1;
    }
    else{
        long long r;
        r = lgput (a, b/2);
        if (b%2 == 0){
            return 1LL*r*r%MOD;
        }
        else{
            return 1LL*a*r*r%MOD;
        }
    }
}

void solve (long long n, long long &nrdiv, long long &sumadiv){
    long long i, e, x, d;
    nrdiv = sumadiv = 1;
    for (i=1; 1LL*p[i]*p[i]<=n && n!=1; i++){
        if (n%p[i] == 0){
            e = 1;
            while (n%p[i] == 0){
                e++;
                n /= p[i];
            }
            nrdiv = 1LL * nrdiv * e;
            x = lgput (p[i], e) - 1;
            if (x < 0)
                x += MOD;
            x = 1LL * x * lgput ((p[i]+MOD-1)%MOD, MOD-2)%MOD;
            sumadiv = 1LL * sumadiv * x % MOD;
        }
    }
    if (n != 1){
        d = n%MOD;
        nrdiv *= 2;
        x = lgput (d, 2) - 1;
        if (x < 0)
            x += MOD;
        x = 1LL * x * lgput ((d+MOD-1)%MOD, MOD-2)%MOD;
        sumadiv = 1LL * sumadiv * x % MOD;
    }
}

void precalc (){
    int i, j;
    for (i=2; i<=1000000; i++){
        if (f[i] == 0){
            p[++m] = i;
            for (j=i+i; j<=1000000; j+=i){
                f[j] = 1;
            }
        }
    }
}

int main(){
    precalc();
    fin >> t;
    for (;t--;){
        fin >> n;
        solve(n, a, b);
        fout << a << " " << b << "\n";
    }
    return 0;
}