Cod sursa(job #1891522)

Utilizator AlexVulpoiuAlexandru Vulpoiu AlexVulpoiu Data 24 februarie 2017 09:08:15
Problema Suma si numarul divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.44 kb
#include <cstdio>
using namespace std;
bool a[1000001];
short t;
int m,i,p,p1,p2,nd,sd,pr[300001];
int const mod=9973;
long long int x,n;
int putere(int qq,int rr)
{
    int q,r,rez;
    q=qq;
    r=rr;
    rez=1;
    q%=mod;
    while(r)
    {
        if(r%2==1)
            rez=(rez*q)%mod;
        q=(q*q)%mod;
        r/=2;
    }
    return rez;
}
int main()
{
    freopen("ssnd.in","r",stdin);
    freopen("ssnd.out","w",stdout);
    a[0]=a[1]=1;
    m=0;
    for(nd=2;nd<=1000000;nd++)
        if(!a[nd])
        {
            pr[++m]=nd;
            for(sd=nd*2;sd<=1000000;sd+=nd)
                a[sd]=1;
        }
    scanf("%hd",&t);
    while(t)
    {
        scanf("%lld",&n);
        nd=sd=1;
        if(n>1)
            for(i=1;pr[i]*pr[i]<=n && i<=m;i++)
                if(n%pr[i]==0)
                {
                    p=0;
                    while(n%pr[i]==0)
                    {
                        n/=pr[i];
                        p++;
                    }
                    nd*=(p+1);
                    p1=(putere(pr[i],p+1)-1)%mod;
                    p2=putere(pr[i]-1,mod-2)%mod;
                    sd=((sd*p1)%mod*p2)%mod;
                    if(n==1)
                        break;
                }
        if(n>1)
        {
            nd*=2;
            sd=(1LL*sd*(n+1))%mod;
        }
        printf("%d %d\n",nd,sd);
        t--;
    }
    return 0;
}