Pagini recente » Cod sursa (job #2854391) | Cod sursa (job #201092) | Cod sursa (job #1668285) | Cod sursa (job #2253460) | Cod sursa (job #359314)
Cod sursa(job #359314)
#include <stdio.h>
FILE *f,*s;
int p,q,l,i,j,x,y,cat,rez;
struct putere
{
int x;
int y;
};
putere v[2000];
void cautBin()
{
int st=1;
int dr=2000000;
int mj;
while(st<=dr)
{
mj=(st+dr)/2;
cat=0;
y=v[i].x;
while(y<mj)
{
cat+=mj/y;
y*=v[i].x;
}
if(cat==v[i].y)
break;
if(cat<v[i].y)
st=mj+1;
if(cat>v[i].y)
dr=mj-1;
}
if(st>rez)
rez=st;
}
int main()
{
f=fopen("gfact.in","r");
s=fopen("gfact.out","w");
fscanf(f,"%d %d",&p,&q);
x=0;
while(p%2==0)
{
x++;
p/=2;
}
if(x>0)
{
l++;
v[l].x=2;
v[l].y=x;
}
for(i=3;i*i<=p;i+=2)
{
x=0;
while(p%i==0)
{
x++;
p/=i;
}
if(x>0)
{
l++;
v[l].x=i;
v[l].y=x;
}
}
if(p>1)
{
l++;
v[l].x=p;
v[l].y=1;
}
for(i=1;i<=l;i++)
v[i].y*=q;
for(i=1;i<=l;i++)
cautBin();
fprintf(s,"%d",rez);
fclose(s);
return 0;
}