Cod sursa(job #2089868)

Utilizator Claudiu07Pana Claudiu Claudiu07 Data 17 decembrie 2017 12:19:12
Problema Suma si numarul divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.54 kb
#include <iostream>
#include <fstream>
#define ll long long
#define P 9973
using namespace std;
ifstream f("ssnd.in");
ofstream g("ssnd.out");
const int maxn=1000005;
int v[100010],k;
bool prim[maxn+1];

void ciur() { k=0;
    for(int i=4; i<=maxn; i+=2)
        prim[i]=1;
    for(int i=3; i<=maxn; i+=2)
        if(!prim[i]) {
            for(int j=2*i; j<=maxn; j+=i)
                prim[j]=1;
        }
    v[++k]=2;
    for(int i=3; i<=maxn; i+=2)
        if(prim[i]==0) {k++; v[k]=i;}
}
ll pow(ll b,ll p)
{
    if(p==0)
        return 1;
    if(p==1)
        return b;
    ll n=1,pB=b;
    while(p)
    {
        if(p%2==1)
        {
            n=(n*pB)%P;
            p--;
        }
        else
        {
            p/=2;
            pB=(pB*pB)%P;
        }
    }
    return n;
}

void solve(ll n)
{
     int nd=1,sd=1;
       ll i=1;
        while(i<=k && 1LL*v[i]*v[i]<=n)
        {
            if(n%v[i]) {i++; continue;}
            int crt=0;
            while(n%v[i]==0)
            {
                crt++;
                n/=v[i];
            }
            ll nr=(1LL*pow(v[i],crt+1)-1)%P;
            nr=nr%P;
            nd=(nd*(crt+1))%P;
            sd=(((sd*nr)%P)*pow(v[i]-1,P-2)%P)%P;
            i++;
        }
        if(n>1)
        {
            nd=nd*2%P;
            sd=(sd*(n+1))%P;
        }
        g<<nd<<' '<<sd<<'\n';
}
int main()
{
    ciur();
    int t;
    ll N;
    f>>t;
    for(int i=1; i<=t; i++)
    {
        f>>N;
        solve(N);
    }
}