Cod sursa(job #1161583)

Utilizator andrettiAndretti Naiden andretti Data 31 martie 2014 12:24:15
Problema Suma divizorilor Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.36 kb
#include<stdio.h>
#include<algorithm>
#include<vector>
#define pb push_back
#define MOD 9901
#define lim 10100
using namespace std;

int A,B,sol=1;
int sieve[lim+5];
vector<int> l;

void read()
{
    scanf("%d%d",&A,&B);
}

void preproc()
{
    for(int i=2;1LL*i*i<=lim;i++)
     if(!sieve[i*i])
      for(int j=i;1LL*i*j<=lim;j++)
       sieve[i*j]=1;

    for(int i=2;i<=lim;i++)
     if(!sieve[i]) l.pb(i);
}

void gcd(int a,int b,long long &x,long long &y)
{
    if(b==0) {x=1; y=0; return;}
    long long x0,y0;
    gcd(b,a%b,x0,y0);
    x=y0;
    y=x0-1LL*(a/b)*y0; while(y<0) y+=MOD;
    y%=MOD;
}

void update(int f)
{
    int nr,p,add;
    long long x,y;

    for(nr=0;A%f==0;A/=f,nr++);

    nr*=B; nr++; p=1; add=f;
    for(int j=0;(nr>>j);j++)
    {
        if( ((nr>>j)&1) ) p=(1LL*p*add)%MOD;
        add=(1LL*add*add)%MOD;
    }
    p--; if(p<0) p+=MOD;

    gcd(f-1,MOD,x,y);
    while(x<0) x+=MOD; x%=MOD;
    p=(1LL*p*x)%MOD;
    sol=(1LL*sol*p)%MOD;
}

void solve()
{
    for(unsigned int i=0;i<l.size() && 1LL*l[i]*l[i]<=A;i++)
     if(A%l[i]==0) update(l[i]);

     if(A>1) update(A);
}

int main()
{
    freopen("sumdiv.in","r",stdin);
    freopen("sumdiv.out","w",stdout);

    read();
    preproc();
    solve();
    printf("%d",sol);

    fclose(stdin);
    fclose(stdout);
    return 0;
}