Pagini recente » Cod sursa (job #2684556) | Istoria paginii utilizator/1475369147896537415369 | Cod sursa (job #1887764) | Cod sursa (job #2016984) | Cod sursa (job #2149232)
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
int nrz(int x, int f)
{
int s = 0;
while(x >= f) {
x /= f;
s += x;
}
return s;
}
int caut(int b, int p)
{
int st, dr, ans;
st = p * (b - 1);
dr = p * b;
while(st <= dr) {
int m = st + (dr - st) / 2, n = nrz(m, b);
if(n >= p) {
ans = m;
dr = m - 1;
}
else
st = m + 1;
}
return ans;
}
int descompunere(int b, int e)
{
int p = 0, ans = 1;
while(!(b & 1)) {
p++;
b >>= 1;
}
if(p)
ans = max(ans, caut(2, p * e));
int d = 3;
p = 0;
while(d * d <= b && b > 1) {
if(b % d) {
d+=2;
continue;
}
while(!(b % d)) {
p++;
b /= d;
}
ans = max(ans, caut(d, p * e));
p = 0, d += 2;
}
if(b > 1)
ans = max(ans, caut(b, e));
return ans;
}
int main()
{
int b, e;
fin >> b >> e;
fout << descompunere(b, e);
return 0;
}