Cod sursa(job #1004271)
Utilizator | Data | 2 octombrie 2013 14:47:06 | |
---|---|---|---|
Problema | Factorial | Scor | 35 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.48 kb |
#include<stdio.h>
int q,p,st,dr,m,x;
int putere(int x)
{
if(x==0)return 0;
return x/5+putere(x/5) ;
}
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
if(p==0){printf("1\n");return 0;}
st=0;
dr=20000000;
while(st!=dr)
{
m=(st+dr)/2;
x=putere(m);
if(p==x)
{
while(m%5!=0)--m;
printf("%d\n",m);
return 0;
}
else
if(p>x)st=m+1;
else
if(p<x)dr=m;
}
printf("-1\n");
return 0;
}