Cod sursa(job #805981)
| Utilizator | Data | 1 noiembrie 2012 16:17:14 | |
|---|---|---|---|
| Problema | Factorial | Scor | 25 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.59 kb |
#include<stdio.h>
int fact( int n){
int f=5, put=0;
while(n/f>=0){
put=put+n/f;
f=f*5;
}
return put;
}
int main(){
int l1,l2,pp,n,z,p;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
l1=1;
l2=1000000000;
pp=0;
while( l1<=l2&&pp==0){
n=(l1+l2)/2;
z=fact(n);
if(z==p){
pp=1;
n=n-n%5;
}
else
if(z<p)
l1=n+1;
else
l2=n-1;
}
if(pp==0)
printf("-1");
else
if(p==0)
printf("1");
else
printf("%d",n);
return 0;
}
