Cod sursa(job #884860)

Utilizator tzipleatudTudor Tiplea tzipleatud Data 21 februarie 2013 13:38:12
Problema Suma divizorilor Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <fstream>
#define MOD 9901

using namespace std;

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

int A, B;
int ANS=1;
int i;
int P, D;

int LogPow (int B, int P)
{
    if (B>=MOD) B%=MOD;
    int R=1;

    while (P)
    {
        if (P%2)
            R=(R*B)%MOD;

        B=(B*B)%MOD;

        P/=2;
    }

    return R;
}

int main ()
{
    f >> A >> B;
    int Up, Down;

    for (P=2; P*P<=A; P++)
        if (A%P==0)
        {
            D=0;
            while (A%P==0)
            {
                A/=P;
                D++;
            }

            Up=LogPow(P, D*B+1)-1;
            if (Up<0) Up+=MOD;

            Down=((P-1)%MOD!=1?LogPow(P-1, MOD-2):1);
            if (Down<0) Down+=MOD;

            ANS=(ANS*Up)%MOD;
            ANS=(ANS*Down)%MOD;
        }

    if (A>1)
    {
        P=A;
        D=1;

        Up=LogPow(P, D*B+1)-1;
        if (Up<0) Up+=MOD;

        Down=((P-1)%MOD!=1?LogPow(P-1, MOD-2):1);
        if (Down<0) Down+=MOD;

        ANS=(ANS*Up)%MOD;
        ANS=(ANS*Down)%MOD;
    }

    g << ANS << '\n';

    return 0;
}