Pagini recente » Cod sursa (job #2186631) | Cod sursa (job #2544825) | Cod sursa (job #2396644) | Cod sursa (job #2494559) | Cod sursa (job #736480)
Cod sursa(job #736480)
#include <stdio.h>
#include <math.h>
FILE *fin=fopen("factorial.in","r");
FILE *fout=fopen("factorial.out","w");
int p;
int zero (int n){
int i=1,nr=0;
while(pow(5,i)<=n)
{
nr=nr+n/int(pow(5,i));
i++;
}
return nr;
}
int cautare(int st, int dr, int p){
int mij=(st+dr)/2;
if (st==dr)
return st;
if (zero(mij)>=p)
return cautare(st,mij,p);
else
return cautare(mij+1,dr,p);
}
int main(){
fscanf(fin, "%d", &p);
if (p==0)
fprintf(fout, "1");
else
{
if (zero(cautare(4*p,5*p,p))==p)
fprintf(fout, "%d", cautare(4*p,5*p,p));
else
fprintf(fout, "-1");
}
fclose(fin);
fclose(fout);
return 0;
}