Cod sursa(job #756559)

Utilizator tzipleatudTudor Tiplea tzipleatud Data 9 iunie 2012 21:24:18
Problema Suma divizorilor Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#define M 9901LL
#define LL long long

using namespace std;

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

LL A,B,T1=1,i,d;

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;
    while (A%i==0 && A>1)
    {
        A/=i;
        d++;
    }
    T1=T1*(LgPow(i,d*B+1)-1+M)%M;
    T1=T1*(LgPow(i-1,M-2))%M;
}

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