Cod sursa(job #1813113)

Utilizator ancabdBadiu Anca ancabd Data 22 noiembrie 2016 18:34:14
Problema Suma divizorilor Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <fstream>

using namespace std;

ifstream fin ("sumdiv.in");
ofstream fout ("sumdiv.out");

#define MOD 9901

int i, a, b, p, q;
long long rez = 1;

long long putere(long long a,long long b)
{
    long long ans = 1;

    while(b)
    if(b & 1) ans *= a,--b;
    else a *= a, b /= 2;

    return ans;
}

int main()
{
    fin >> a >> b;

    for(int i = 2; i * i <= a; ++i)
    {
        if(a % i) continue;

        p = i;
        q = 0;
        while(a % i == 0)
        {
            ++q;
            a/=i;
        }

        rez *= putere(p, 1LL * b * q + 1) - 1;
        rez *= putere(p - 1, MOD - 2);
    }

    if(a > 1)
    {
        if(a % MOD == 1) rez *= (b + 1);
        else
        {
           rez *= putere(a, b + 1) - 1;
           rez *= putere(a - 1, MOD - 2);
        }
    }

    fout << rez << '\n';
    return 0;
}