Pagini recente » Cod sursa (job #1293715) | Cod sursa (job #260856) | Cod sursa (job #1424014) | Cod sursa (job #268521) | Cod sursa (job #846582)
Cod sursa(job #846582)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("gfact.in");
ofstream g("gfact.out");
long long P, poz = 1, sol;
int Q, put, cnt;
void solve(long long fact, int putere)
{
long long limit = fact, poz = 1;
long long need = 1LL * putere * Q;
cnt = 1;
int pow = 1;
while (cnt < need) {
long long NR = (1LL * limit * fact - fact - limit) / fact; // cate nr sunt divizibile cu fact din (limit, limit * fact)
if (cnt + NR > need) {
poz += need - cnt;
cnt = need;
} else {
cnt += NR;
poz += NR;
limit *= fact;
pow++;
if (cnt < need)
cnt += pow, poz++;
}
}
long long rez = 1LL * fact * poz;
sol = max(sol, rez);
}
int main()
{
f >> P >> Q;
long long aux = P, fact = 2;
while (aux > 1) {
put = 0;
while (aux % fact == 0) {
aux /= fact;
put++;
}
if (put)
solve(fact, put);
fact++;
}
g << sol << '\n';
return 0;
}