Cod sursa(job #925730)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 24 martie 2013 18:22:52
Problema Suma divizorilor Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.44 kb
#include <iostream>
#include <fstream>

using namespace std;

#define modulo 9901

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

int A, B;

int putere( int a, int p ){

    int res = 1;

    for ( int i = 0; ( 1 << i ) <= p; ++i ){

        if ( ( 1 << i ) & p )
            res = ( res * a ) % modulo;

        a = ( a * a ) % modulo;
    }

    return res;
}

void rezolva(){

    long long S = 1, e = 0;

    for ( int d = 2; d * d <= A && A > 1; ++d ){

        if ( A % d )
            continue;

        e = 0;

        while ( A % d == 0 )
            A /= d,
            e++;

        if ( d % modulo == 1 )
            S *= 1LL * ( e + 1 ) % modulo;
        else{
                int p1 = ( putere ( d, e * B + 1 ) + modulo - 1 ) % modulo;
                int p2 = putere( d - 1, modulo - 2 ) % modulo;

                S *= 1LL * p1 * p2;
                S %= modulo;
        }
    }

    if ( A > 1 ){

        if ( A % modulo == 1 )
            S = ( S * 1LL * ( B % modulo + 1 ) ) % modulo;
        else{
                int p1 = ( putere ( A, B + 1) + modulo - 1 ) % modulo;
                int p2 = putere ( A - 1, modulo - 2 ) % modulo;

                S *= 1LL * p1 * p2;
                S %= modulo;
        }
    }

    g << S << "\n";

    g.close();
}

void citire(){

   f >> A >> B;

   f.close();
}


int main(){

    citire();
    rezolva();

    return 0;
}