Cod sursa(job #1449058)

Utilizator iulianrotaruRotaru Gheorghe-Iulian iulianrotaru Data 8 iunie 2015 18:11:22
Problema Suma divizorilor Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <fstream>
#include <bitset>
#define Xp 9901
using namespace std;
ifstream f("sumdiv.in");
ofstream g("sumdiv.out");
int a,b,p[Xp];
bitset <Xp> w;
long long int query(long long int x,long long int y)
{
    long long put=1;
    while(y) {if(y&1) put=(1LL*x*put)%Xp,y--; x=(1LL*x*x)%Xp; y/=2;}
    if (put<0) return put+=Xp;
    return put;
}
int main()
{
    f>>a>>b;
    if(!a) g<<0;
    else if(!b||a==1) g<<1;
    else
    {
        p[1]=2; long long i,j,poz=1,suma=1,m=1,exp;
        for(i=3;i<=Xp;i+=2)
            if(!w[i])
        {
            p[++m]=i;
            for(j=i*i;j<=Xp;j+=(i<<1)) w[j]=1;
        }
        while(p[poz]*p[poz]<=a)
        {
            exp=0;
            while(a%p[poz]==0) {exp++; a/=p[poz];}
            if(exp!=0) suma=(1LL*suma*((query(p[poz]%Xp,exp*b+1)-1)/(p[poz]-1)))%Xp;
            poz++;
        }
        if(a>1) suma=(1LL*suma*((query(a%Xp,b+1)-1)/(a-1))*(query(a-1,Xp-2)))%Xp;
        g<<suma;
    }
    g.close();
    return 0;
}