Pagini recente » Cod sursa (job #1146756) | Cod sursa (job #2158369) | Cod sursa (job #871644) | Cod sursa (job #1179159) | Cod sursa (job #438124)
Cod sursa(job #438124)
#include<stdio.h>
long i , j , x , n , p , q , pi [10001] , pp[10001] ;
void div()
{
int putere;
for(i=2;i*i<=p;i++)
{
putere=0;
while(p%i==0)
{
putere++;
p/=i;
}
if(putere==0)
continue;
pi[++j]=i;
pp[j]=putere*q;
}
if(p!=1)
{
pi[++j]=p;
pp[j]=q;
}
}
int put(int x,int y)
{
int xy=0;
while(x)
{
xy+=x/y;
x/=y;
}
return xy;
}
bool verif(int n)
{
for(i=1;i<=j;i++)
if(put(n,pi[j])<pp[i])
return 0;
return 1;
}
int caut()
{
long long x;
long long pas=1<<60;
for(x=0;pas;pas>>=1)
{
if(!verif(x+pas))
x+=pas;
}
return x;
}
int main()
{
freopen("gfact.in","r",stdin);
freopen("gfact.out","w",stdout);
scanf("%ld%ld",&p,&q);
div();
p=1;
printf("%d",caut()+1);
return 0;
}