Cod sursa(job #2080263)

Utilizator Stefan_RaduStefan Radu Stefan_Radu Data 2 decembrie 2017 17:48:42
Problema Suma divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.5 kb
#include <fstream>
 
using namespace std;
 
ifstream cin("sumdiv.in");
ofstream cout("sumdiv.out");
 
const int MOD = 9901;
 
long long Raise(long long a, int p) {
 
  long long ans = 1;
  while (p) {
    if (p & 1) {
      ans = (ans * a) % MOD;
    }
 
    a = (a * a) % MOD;
    p >>= 1;
  }
 
  return ans;
}
 
void Inv_mod(int a, int b, long long &x, long long &y) {
 
  if (not b) {
    x = 1;
    y = 0;
    return; 
  }
  long long x0, y0;
  Inv_mod(b, a % b, x0, y0);
  x = y0;
  y = x0 - (a / b) * y0;
}
 
void Solve(int a, int b) {
 
  long long s = 1ll;
  for (int i = 2; i * i <= a; i ++) {
    if (a % i) {
      continue;
    }
 
    int cur_exp = 0;
    while (a % i == 0) {
      a /= i;
      cur_exp ++;
    } 
     
    cur_exp *= b;
    if (i % MOD == 1) {
      s = s * (cur_exp + 1) % MOD;
    }
    else if (i % MOD) {
      long long cur_nr = Raise(i, cur_exp + 1);
      long long x, y;
      Inv_mod(i - 1, MOD, x, y);
      while (x < 0) {
        x += MOD;
      }
      
      s = (s * (cur_nr - 1) * x) % MOD;
    }
  }
 
  if (a != 1) {
     
    if (a % MOD == 1) {
      s = (s * (b + 1)) % MOD;
    }
    else if (a % MOD) {
      long long cur_nr = Raise(a, b + 1);
      long long x, y;
      Inv_mod(a - 1, MOD, x, y);
      while (x < 0) {
        x += MOD;
      }
     
      s = (s * (cur_nr - 1) * x) % MOD;
    }
 }
 
  cout << s << '\n';
}
 
int main(int argc, char const *argv[]) {
   
  int a, b;
  cin >> a >> b;
  if (a == 0) {
    cout << 0 << '\n';
    return 0;
  }
  Solve(a, b);
}