Cod sursa(job #526435)
| Utilizator | Data | 28 ianuarie 2011 12:41:06 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.42 kb |
#include<stdio.h>
int n,p;
int nr0(int x)
{
int nr=0;
while(x)
{
nr+=x/5;
x/=5;
}
return nr;
}
int caut()
{
int i,pas=1<<30;
for(i=0;pas!=0;pas>>=1)
if(nr0(i+pas)<p)
i+=pas;
return i+1;
}
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
int i = caut();
if(nr0(i)==p)
printf("%d",i);
else
printf("-1");
return 0;
}
