Pagini recente » Cod sursa (job #921912) | Cod sursa (job #2327528) | Cod sursa (job #1655140) | Cod sursa (job #123654) | Cod sursa (job #2799214)
#include <stdio.h>
#include <stdlib.h>
int check(int x,int p)
{
long long k,ok;
k=5;
ok=0;
while(k<=x)
{
ok+=x/k;
k=k*5;
}
if(p==ok)
return 1;
else
return 0;
}
int main()
{
FILE *fin,*fout;
fin=("fact.in","r");
fout=("fact.out","w");
long long h,x,p;
int gr;
fscanf(fin,"%d",&p);
x=p;
h=1;
gr=1;
if(x>=1)
{
while(h*5+1<x)
{
h=(h*5)+1;
gr++;
}
while(h!=1)
{
x-=(x/h);
h--;
h=h/5;
}
x=x*5;
if(check(x,p))
fprintf(fout,"%d",x);
else
fprintf(fout,"-1");
}
else if(p==0)
fprintf(fout,"1");
fclose(fin);
fclose(fout);
return 0;
}