Cod sursa(job #324654)
| Utilizator | Data | 16 iunie 2009 17:04:11 | |
|---|---|---|---|
| Problema | Factorial | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.5 kb |
#include<fstream.h>
int first, last, p, mid;
int zero(int x)//care 0 are x!
{
int p5 = 5;
int d = 0;
while (x/p5 != 0) {
d += (x/p5);
p5*=5;
}
return d;
}
int main()
{
// cout<<zero(25);
ifstream in("fact.in");
ofstream out("fact.out");
in>>p;
first = 1; last = 6*p;
while (first<=last) {
mid = first + (last-first)/2;
if (zero(mid)>=p)
last = mid - 1;
else
first = mid + 1;
}
if(first==p)
out<<first;
else
out<<"-1";
return 0;
}