Pagini recente » Cod sursa (job #2292591) | Cod sursa (job #1499866) | Cod sursa (job #106766) | Cod sursa (job #3127731) | Cod sursa (job #1810764)
#include <stdio.h>
#include <stdlib.h>
#define Pr 4675000
int fact[Pr+1][2];
unsigned long long int nr(unsigned long long int n,int q)
{
unsigned long long int s=0;
while(n>0)
{
n=n/q;
s+=n;
}
return s;
}
char verif(unsigned long long int n,int q)
{
int i=1,x=1;
while(i<=q && x==1)
{
if(nr(n,fact[i][0])<fact[i][1])
x=0;
i++;
}
return x;
}
int main()
{
int n,k,d,q;
unsigned long long int step=1,r;
FILE*fi,*fo;
fi=fopen("gfact.in","r");
fo=fopen("gfact.out","w");
fscanf(fi,"%d%d",&n,&k);
d=2;
q=0;
while(n>1){
if(n%d==0)
{
if(fact[q][0]!=d){
fact[q][1]*=k;
q++;
}
n=n/d;
fact[q][0]=d;
fact[q][1]++;
}
else {
d++;
}
}
fact[q][1]*=k;
step=step<<63;
r=0;
while(step>0)
{
if(verif(r+step,q)==0)
r+=step;
step/=2;
}
fprintf(fo,"%d",r+1);
fclose(fi);
fclose(fo);
return 0;
}