Cod sursa(job #772187)
| Utilizator | Data | 28 iulie 2012 18:03:11 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.66 kb |
#include<fstream>
using namespace std;
long zero(long x)
{ long putere=1, z=0;
while (putere<=x)
{ putere*=5;
z+=x/putere; }
return z; };
int main () {
ifstream f1("fact.in");
ofstream f2("fact.out");
long p,st,dr,m;
f1>>p;
st=1; dr=5*p;
while (st<=dr)
{ m=(st+dr)/2;
if (p<= zero(m))
dr=m-1;
else st=m+1; }
if (zero(st)==p)
f2<<st;
else f2<<-1;
f1.close();
f2.close();
return 0; }
