Pagini recente » Cod sursa (job #1961613) | Cod sursa (job #698672) | Cod sursa (job #1905686) | Cod sursa (job #562455) | Cod sursa (job #2767319)
#include <bits/stdc++.h>
using namespace std;
long long exp(int a, int b) {
if (b == 0) return 1 % 9901;
if (b % 2 == 0) return exp(a*a, b / 2) % 9901;
return a*exp(a*a, b/2) % 9901;
}
long long exp2(int a, int b) {
if (b == 0) return 1;
if (b % 2 == 0) return exp2(a*a, b / 2);
return a*exp2(a*a, b/2);
}
int gcd(int a, int b, int &x, int &y) {
if (b==0) {
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = gcd(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
return d;
}
int main()
{
ifstream fin("sumdiv.in");
ofstream fout("sumdiv.out");
int a, b;
fin >> a >> b;
vector<int> prime;
vector<bool> prim(100001, true);
for (int i = 2; i <= 100000; i++) {
if (prim[i] == true) {
prime.push_back(i);
for (int j = i * 2; j <= 100000; j += i)
prim[j] = false;
}
}
long long number = 1, sum = 1, d = 0;
while (a > 1 && prime[d] * prime[d] <= a) {
long long p = 1, count = 0;
while (a % prime[d] == 0) {
p = (p * prime[d]) % 9901;
a /= prime[d];
count++;
}
//cout << count << '\n';
int copy = b;
if (count != 0) {
p = exp(prime[d], copy * count);
//cout << p << '\n';
//if (count > 1)
//p *= p1;
//else
//p = p1;
int tmp = (prime[d] - 1) % 9901;
int x, y;
int D = gcd(tmp, 9901, x, y);
while (x < 0)
x+=9901;
int inv = x / D;
sum = (sum * ((((p * prime[d]) % 9901) - 1) * inv)) % 9901;
cout << p << ' ' << inv << ' ' << sum << '\n';
}
d++;
}
if (a != 1) {
//cout << "aici\n";
int copy = b;
long long p = 1;
p = exp(a, copy);
int tmp = (a - 1) % 9901;
int x, y;
int D = gcd(tmp, 9901, x, y);
while (x < 0)
x+=9901;
int inv = x / D;
sum = (sum * ((((p * a) % 9901) - 1) * inv)) % 9901;
}
fout << sum << '\n';
return 0;
}