Cod sursa(job #876823)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 12 februarie 2013 10:45:36
Problema Suma divizorilor Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.5 kb
#include <iostream>
#include <fstream>
#include <bitset>

using namespace std;

#define Nmax 11000
#define modulo 9901

int div[Nmax >> 2];
char ciur[Nmax*Nmax/2];
int A, B, res = 1, l, A1;

void gen(){

    div[++l] = 2;

    for(int i = 3; i < Nmax; i += 2){

        if(ciur[i >> 4] & (1 << ((i >> 1) & 7)))
            continue;

        div[++l] = i;

        for(int j = i + (i << 1); j < Nmax; j += (i << 1))
            ciur[j >> 4] |= ( 1 << ((j >> 1) & 7) ) ;
    }
}

inline int putere(int a, int b){

    int result = 1;

    a %= modulo;

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

        if( (1 << i) & b )
            result = (result * a) % modulo;

        a = (a * a) % modulo;
    }

    return result;
}

int prog(int a, int b){

    if( a % modulo == 1)
        return b * B + 1;
    else
        return ( putere ( a, b * B + 1 ) + 9900 ) * ( putere ( a-1, 9899) ) % modulo;
}

void citire(){

    ifstream f("sumdiv.in");

    f >> A >> B;
    A1 = A;

    f.close();
}

void rezolva(){

    for(int i = 1, p = 0; div[i] * div[i] <= A; i++)
        if(A % div[i])
            continue;

        else{
                for(p = 0 ; A1 % div[i] == 0 ; A1 /= div[i], p++);

                if(p)
                    res = ( res * prog ( div[i], p ) ) % modulo;
            }

     if(A1)
        res = ( res * prog ( A1, 1 ) ) % modulo;
}

void afis(){

    ofstream g("sumdiv.out");

    g << res << "\n";

    g.close();
}


int main(){

    citire();
    gen();
    rezolva();
    afis();

    return 0;
}