Cod sursa(job #2836836)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 20 ianuarie 2022 23:12:46
Problema Suma divizorilor Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <bits/stdc++.h>

using namespace std;

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

const int mod = 9901;

void multSelf(int &x, const int &y) {
  x = x * y % mod;
}

int mult(int x, const int &y) {
  multSelf(x, y);
  return x;
}

int Pow(int x, int n) {
  int ans = 1;
  while (n) {
    if (n & 1) {
      ans = mult(ans, x);
    }
    multSelf(x, x);
    n >>= 1;
  }
  return ans;
}

void testCase() {
  int a, b, ans = 1;
  fin >> a >> b;
  int d = 2;
  while (a > 1) {
    int e = 0;
    while (a % d == 0) {
      e += 1;
      a /= d;
    }
    if (e) {
      e *= b;
      multSelf(ans, mult((Pow(d % mod, e + 1) - 1 + mod) % mod, Pow((d - 1) % mod, mod - 2)));
    }
    if (d == 2) {
      d = 3;
    } else {
      d += 2;
    }
    if (d * d > a) {
      d = a;
    }
  }
  fout << ans << '\n';
}

int main() {
  int tests = 1;
  for (int tc = 0; tc < tests; ++tc) {
    testCase();
  }
  fin.close();
  fout.close();
  return 0;
}