Cod sursa(job #2064596)

Utilizator cella.florescuCella Florescu cella.florescu Data 12 noiembrie 2017 16:08:48
Problema Suma divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <bits/stdc++.h>

using namespace std;

const int MOD = 9901;

inline int my_pow(int base, long long expo) {
  int ans = 1;
  for (expo = expo; expo > 0; expo >>= 1, base = (base * base) % MOD)
    if (expo & 1)
      ans = (ans * base) % MOD;
  return ans;
}

int expr(int d, int e, int b) {
  if (d == 0)
    return 1;
  if (d == 1)
    return (1LL * e * b + 1) % MOD;
  return (1LL * (my_pow(d, 1LL * e * b + 1) - 1 + MOD) * my_pow(d - 1, MOD - 2)) % MOD;
}

int main()
{
    int a, b;
    ifstream fin("sumdiv.in");
    fin >> a >> b;
    fin.close();
    int ans = 1;
    for (int d = 2; d * d <= a; ++d)
      if (a % d == 0) {
        int e = 0;
        while (a % d == 0) {
          a /= d;
          ++e;
        }
        ans = (ans * expr(d % MOD, e, b)) % MOD;
      }
    if (a > 1)
      ans = (ans * expr(a % MOD, 1, b)) % MOD;
    if (b == 0)
      ans = 1;
    ofstream fout("sumdiv.out");
    fout << ans;
    fout.close();
    return 0;
}