Cod sursa(job #1312988)
| Utilizator | Data | 10 ianuarie 2015 11:13:58 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.68 kb |
#include <fstream>
using namespace std;
int t,p,dr,stg,n,pu;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
fin>>p;
stg=1;
dr=2147483647;
if(p==0)
fout<<"1";
else
{
while((t!=p)&&(stg<dr))
{
n=(stg+dr)/2;
t=0;
pu=5;
while(pu<=n)
{
t=t+n/pu;
pu=pu*5;
}
if(t>p)
dr=n-1;
else
if(t<p)
stg=n+1;
}
n=n-n%5;
if(t==p)
fout<<n;
else
fout<<"-1";
}
return 0;
}
