Cod sursa(job #756710)

Utilizator Theorytheo .c Theory Data 10 iunie 2012 12:20:59
Problema Suma divizorilor Scor 80
Compilator cpp Status done
Runda Remember Mihai Pătrașcu Marime 1.24 kb
#include<fstream>
#define mod 9901
#define ll long long
using namespace std;
ifstream fin("sumdiv.in");
ofstream fout("sumdiv.out");
long long A, B, S;

long long put(ll a, ll b)
{
    if(!b) return 1;
    if(b % 2)
        return (a * put(a,b - 1)) % mod;
    long t = put(a, b/2) % mod;
    return (t * t) %mod;
}
long long desc(ll x, ll nr)
{
    nr *= B;
    ll aux1 = (put(x, nr + 1) - 1+ mod ) % mod;



    ll aux2 = put(x - 1, mod - 2) % mod;

    return (aux1 * aux2) %mod;
}
void read()
{
    S = 1;
    fin >>A>>B;
    if(A %  mod ==0 || A == 1|| B == 0 )
    {
        fout<< 1; return ;
    }
    if( A == 0)
    {
        fout<< 0 ; return ;
    }

    for(int i = 2; i * i <= A and A > 1 ; ++i)
    {
        if(A % i == 0)
        {
           ll nr = 0;
            while(A % i == 0 && A > 1)
                A /= i, ++nr;
            if(i % mod == 1){
             S = S * (nr * B + 1)% mod;
             continue;
            }
            long long K = desc(i, nr) %mod;

            S = (S * K )% mod;
        }

    }
    //fout << put( 2, 10) ;
    if(A != 1)
        S = (S * desc(A, 1)) % mod;
    fout <<S;

}
int main()
{

    read();
    fin.close();
    return 0;
}