Cod sursa(job #764030)
| Utilizator | Data | 3 iulie 2012 20:15:59 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <stdio.h>
#include <iostream>
using namespace std;
long P,N,tmp,zeros;
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
cin >> P;
if (P==0) cout << "1";
else
{
// se arata usor ca daca N! are cel putin N zerouri, atunci N>= 4P
tmp=N=4*P;
while (tmp/5 > 0)
{ tmp=tmp/5; zeros+=tmp;}
while (zeros < P)
if ((++N)%5==0)
{
++zeros; tmp=N/5;
while (tmp%5 ==0)
{
++zeros; tmp/=5;
}
}
if (zeros > P) cout << "-1";
else cout << N;
}
return 0;
}
