Pagini recente » Cod sursa (job #2517644) | Cod sursa (job #2519784) | Cod sursa (job #2759397) | Cod sursa (job #2110824) | Cod sursa (job #2799215)
#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=fopen("fact.in","r");
fout=fopen("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;
}