Cod sursa(job #687672)
| Utilizator | Data | 22 februarie 2012 17:52:08 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.56 kb |
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
int main ()
{
ifstream f("fact.txt");
ofstream g("fact2.txt");
long long x,p,n,m,s,d,ok=0,nr;
f>>p;
if(p==0) g<<1;
else
{
s=0;
d=p*5;
while(s<=d)
{
m=(s+d)/2;
nr=m;
x=0;
while(nr)
{
x=x+nr/5;
nr/=5;
}
if(x==p)
ok=1;
if(x>=p)
d=m-1;
else
s=m+1;
}
if(ok==1)
{
if(m%5!=0)
while(m%5!=0)
m++;
g<<m;
}
else
g<<-1;
}
return 0;
}