Cod sursa(job #1340351)

Utilizator MaarcellKurt Godel Maarcell Data 11 februarie 2015 19:32:04
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.44 kb
#include <iostream>
#include <fstream>
#define prim 9973LL
#define MAXN 1000000
#define LL long long int
using namespace std;

int T,K; LL f[100],d[100], p[100000]; bool v[MAXN+10];

void sieve(){
    int i,j;
    for (i=2; i<=MAXN; i++)
        if (!v[i]){
            p[++K]=i;
            for (j=2*i; j<=MAXN; j+=i)
                v[j]=1;
        }
}

LL fpow(LL x, LL p){
    LL res=1;
    x%=prim;

    while (p>0){
        if (p&1)
            res=(res*x)%prim;

        x=(x*x)%prim;
        p>>=1;
    }

    return res;
}

int main(){
    ifstream fin("ssnd.in");
    ofstream fout("ssnd.out");
    fin >> T;

    sieve();
    LL i,N,cnt,L,sum;
    while (T--){
        fin >> N;
        if (N==1){
            fout << 1 << " " << 1 << "\n";
            continue;
        }

        cnt=sum=1;
        L=0;
        for (i=1; i<=K && N!=1; i++)
            if (N%p[i]==0){
                f[++L]=p[i];
                d[L]=0;
                while (N%p[i]==0) N/=p[i],d[L]++;
            }

        if (N!=1){
            f[++L]=N;
            d[L]=1;
        }


        for (i=1; i<=L; i++)
            cnt*=(d[i]+1);

        for (i=1; i<=L; i++)
            if (f[i]%prim==1)
                sum=(sum*(d[i]+1))%prim;
            else
                sum=(sum*((fpow(f[i],d[i]+1)-1+prim)%prim)*(fpow(f[i]-1,prim-2)))%prim;

        fout << cnt << " " << sum << "\n";
    }

    return 0;
}