Mai intai trebuie sa te autentifici.
Cod sursa(job #1156535)
| Utilizator | Data | 27 martie 2014 19:17:07 | |
|---|---|---|---|
| Problema | Factorial | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.73 kb |
#include <cstdio>
using namespace std;
const int MAX=2000000000;
int fact(int x);
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int p;
scanf("%d",&p);
if(p==0)
{
printf("1\n");
return 0;
}
int dr;
dr=fact(MAX);
int i, step;
for (step = 1; step < dr; step <<= 1);
for (i = 0; step; step >>= 1)
if (fact(i + step)<= dr && fact(i+step)<=p)
i += step;
if(i)
{
while(i%5)i--;
printf("%d\n",i);
}
else
printf("-1\n");
return 0;
}
int fact(int x)
{
int a=5,rez=0;
while(x/a)
{
rez+=x/a;
a*=5;
}
return rez;
}
