Cod sursa(job #2195724)

Utilizator AndreiVisoiuAndrei Visoiu AndreiVisoiu Data 17 aprilie 2018 11:35:56
Problema Suma divizorilor Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.5 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int sqrtN = 7072,
          MOD = 9901,
          primes = 908;

int p[primes+1], k = 1;
bool b[sqrtN+1];

void ciur(int n) {
    b[0] = b[1] = 1;
    for(int i = 4; i <= n; i += 2)
        b[i] = 1;
    for(int i = 3; i*i <= n; i++)
        if(!b[i])
            for(int j = i*i; j <= n; j += i)
                b[j] = 1;
    p[1] = 2;
    for(int i = 3; i <= n; i += 2)
        if(!b[i])
            p[++k] = i;
}

long long putere(long long x, int p) {
    long long a = 1;
    while(p > 0) {
        while(p%2 == 0) {
            x = x*x%MOD;
            p /= 2;
        }
        a = a*x % MOD;
        p--;
    }
    return a;
}
int main()
{
    ciur(sqrtN);
    int a, b;
    in >> a >> b;
    long long sDiv = 1;
    for(int d = 1; p[d]*p[d] <= a; d++) {
        if(a%p[d] == 0) {
            int c = 0;
            while(a%p[d] == 0) {
                a /= p[d];
                c++;
            }
            c *= b;
            if(p[d] == MOD) continue;

            if(p[d]%MOD == 1)
                sDiv = sDiv*(p[d]+1)%MOD;
            else
                sDiv = sDiv*(putere(p[d], c+1)-1)%MOD * putere(p[d]-1, MOD-2)%MOD;
        }
    }
    if(a > 1)
        if(a%MOD == 1)
            sDiv = sDiv*(b+1)%MOD;
        else
            sDiv = sDiv*(putere(a, b+1)-1)%MOD * putere(a-1, MOD-2)%MOD;
    out << sDiv;
    return 0;
}