Pagini recente » Cod sursa (job #2710151) | Cod sursa (job #2850727) | Cod sursa (job #2838907) | Cod sursa (job #3199142) | Cod sursa (job #178404)
Cod sursa(job #178404)
#include<fstream.h>
int conditie (int a,int p, int e)
{
int nr=0,l=p;
for (;p<=a;p=p*l)
nr+=a/p;
if (nr<e) return 1;
else if (nr==e && a%l==0) return 1;
return 0;
}
int cautbin(int a, int b)
{
int p=1,i=0;
for (;p*2<=a*b;p*=2);
for (;p;p/=2)
if (p+i<=b*a && conditie(p+i,a,b)) i+=p;
return i;
}
int main()
{
int nr,l,p,q,i,max=0;
ifstream f("gfact.in");
f>>p>>q; f.close();
i=2;
while (i<=p)
{
if (p%i==0) {
nr=0;
for (;p%i==0;nr++,p/=i);
nr*=q;
l=cautbin(i,nr);
if (l%i!=0) l++;
if (l>max) max=l;
}
i++;
}
ofstream g("gfact.out");
g<<max;g.close();
return 0;
}