Pagini recente » Cod sursa (job #2113992) | Istoria paginii utilizator/georgiana_m | Cod sursa (job #529890) | Cod sursa (job #260156) | Cod sursa (job #73414)
Cod sursa(job #73414)
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int p, q, nr;
long long bmax, bi;
int wop(int a, int b){
int s = 1;
for (int i=1; i<=b; i++)
s*=a;
return s;
}
struct ches{
int b, e;
};
ches v[1000];
int comp(const void*x, const void*y){
ches xx=*(ches*)x, yy=*(ches*)y;
int a1 = wop(xx.b, xx.e), a2 = wop(yy.b, yy.e);
if (a1<a2) return -1;
if (a1>a2) return 1;
return 0;
}
int main()
{
freopen("gfact.in","r",stdin);
freopen("gfact.out","w",stdout);
int i, sqr, k, p1;
scanf("%d%d", &p, &q);
sqr = sqrt(p);
p1 = p;
for (i=2;i<=sqr;i++)
if (p1%i==0){
v[++nr].b = i;
k = 0;
do{
k++;
p1/=i;
}
while (p1%i==0);
v[nr].e = k;
}
if (p1!=1){
v[++nr].b = p1;
v[nr].e = 1;
}
for (i=1; i<=nr; i++){
int li = 1, ls =q*v[i].e, s, pz, a;
long long bind = 20000000*1000;
while (li<=ls){
pz = (li+ls)/2;
bi = v[i].b*pz;
a = v[i].b;
s = 0;
while (bi/a != 0){
s+=bi/a;
a*=v[i].b;
}
if (s >= q*v[i].e){
if (bi < bind)
bind = bi;
ls = pz-1;
}
else
li = pz+1;
}
if (bind > bmax)
bmax = bind;
}
printf("%lld\n", bmax);
fclose(stdin);
fclose(stdout);
return 0;
}