Cod sursa(job #1810233)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 19 noiembrie 2016 19:35:23
Problema Suma divizorilor Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <fstream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

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

const int mod = 9901;

int Pow(int who, int pow) {

    int ret = 1;
    while (pow) {
        if (pow & 1)
            ret = ret * who % mod;
        pow >>= 1;
        who = who * who % mod;
    }

    return ret;
}

int main() {

    int a, b; fin >> a >> b;
    int ans = 1;

    for (int i = 2; i * i <= a; ++i) {
        if (a % i)
            continue;

        int cnt = 0;
        while (a % i == 0)
            a /= i, ++cnt;

        ans = ans * (Pow(i, cnt * b + 1) - 1) % mod;
        ans = ans * Pow(i - 1, mod - 2) % mod;

    }

    if (a != 1) {

        if (a % mod == 1)
            ans = 1LL * ans * (1 + b) % mod;
        else {
            ans = ans * (Pow(a, b + 1) - 1) % mod;
            ans = ans * Pow(a - 1, mod - 2) % mod;
        }

    }

    while (ans < 0)
        ans += mod;

    fout << ans << '\n';

    return 0;

}

//Trust me, I'm the Doctor!