Cod sursa(job #2388982)

Utilizator PaterucAPetruc Andrei Stefan PaterucA Data 26 martie 2019 18:49:18
Problema Suma si numarul divizorilor Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.2 kb
#include <bits/stdc++.h>

using namespace std;

ifstream inf("ssnd.in");
ofstream outf("ssnd.out");

const int M=9973;

bool c[1000010];
vector<int> p(1e6+3, 0);

long long s1;
int s2;

int t, cnt;
long long n;

int putere(int b, int e)
{
    if(e==0)
        return 1;
    int ret=putere(b,e/2);
    ret=(1LL*ret*ret)%M;
    if(e&1)
        ret=(ret*b)%M;
    return ret;
}
int main()
{
    for(int i=2; i<=1e6; i++)
    {
        if(!c[i])
        {
            p[++cnt]=i;
            for(int j=i*2; j<=1e6; j+=i)
                c[j]=1;
        }
    }
    inf>>t;
    for(;t;t--)
    {
        s1=1;
        s2=1;
        inf>>n;
        /*if(!c[n])
        {
            outf<<2<<' '<<n+1<<'\n';
            continue;
        }*/
        int e=0;
        for(int d=1; d<=cnt&&p[d]*p[d]<=n; d++,e=0)
        {
            while(!(n%p[d]))
                n/=p[d],e++;
            s1*=(e+1);
            s2=(1LL*s2*(putere(p[d],e+1)-1)*(putere(p[d]-1,M-2)%M))%M;
        }
        if(n>1)
        {
            s1=(s1*2)%M;
            s2=(1LL*s2*(putere(n,2)-1)*(putere(n-1, M-2)%M))%M;
        }
        outf<<s1<<' '<<s2<<'\n';
    }
    return 0;
}