Cod sursa(job #756535)

Utilizator tzipleatudTudor Tiplea tzipleatud Data 9 iunie 2012 20:56:29
Problema Suma divizorilor Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>
#define M 9901
#define LL long long

using namespace std;

ifstream f("sumdiv.in");
ofstream g("sumdiv.out");

LL A,B,T1=1,T2=1,i,d,x,y;

LL LgPow (LL b, LL p)
{
    LL R,X,i;
    for (i=1,R=1,X=b;i<=p;i<<=1)
    {
        if (i&p) R=R*X%M;
        X=X*X%M;
    }
    return R%M;
}

void Div (LL i)
{
    d=0;
    T2=T2*(i-1)%M;
    while (A%i==0 && A>1)
    {
        A/=i;
        d++;
    }
    T1=T1*(LgPow(i,d*B+1)-1)%M;
}

void IM (LL &x, LL &y, LL a, LL b)
{
    if (!b)
    {
        x=1;
        y=0;
    }
    else
    {
        IM(x,y,b,a%b);
        LL aux=x;
        x=y;
        y=aux-y*(a/b);
    }
}

int main()
{
    f >> A >> B;
    for (i=2;i*i<=A && A>1;i++)
        if (A%i==0)
            Div(i);
    if (A>1) Div(A);
    x=y=0;
    IM(x,y,T2,M);
    if (x<=0) x=M+x%M;
    T1=T1*T2%M;
    g << T1 << '\n';
    f.close();g.close();
    return 0;
}