Cod sursa(job #2565296)

Utilizator Teo_1101Mititelu Teodor Teo_1101 Data 2 martie 2020 13:30:19
Problema Suma divizorilor Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <bits/stdc++.h>

using namespace std;

const int MOD = 9901;

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

int x, K;

int Exp( int x, long long p )
{
    if( p == 0 ) return 1;

    int ans = Exp( x, p/2 );
    ans = ( 1LL * ans * ans)%MOD;

    if( p%2 == 0 ) return ans;
    else return ( 1LL * x * ans )%MOD;
}
int Inv( int x )
{
    return Exp( x, MOD-2 );
}
void SumDiv( int x )
{
    long long p;
    long long D = 1;

    for( int i = 2; i*i <= x; ++i )
    {
        if( x%i == 0 )
        {
            p = 0;
            while( x % i == 0 )
            {
                x /= i;
                p++;
            }
            p*=K;

            int exp = Exp( i, p+1 )-1;
            if( exp < 0 )exp += MOD;

            D = ( 1LL * D * exp )%MOD;
            D = ( 1LL * D * Inv( i-1 ) );

        }
    }

    if( x > 1 )
    {
        int exp = Exp( x, K+1 )-1;
        if( exp < 0 )exp += MOD;

        D = ( 1LL * D * exp )%MOD;
        D = ( 1LL * D * Inv( x-1 ) )%MOD;
    }
    fout << D;
}

void Solve()
{
    fin >> x >> K;

    SumDiv( x );
}
int main()
{
    Solve();
    return 0;
}