Cod sursa(job #1312979)
| Utilizator | Data | 10 ianuarie 2015 11:05:02 | |
|---|---|---|---|
| Problema | Factorial | Scor | 85 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <fstream>
using namespace std;
long long dr,stg,n,pu;
int t,p;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
fin>>p;
stg=1;
dr=9223372036854775807;
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;
else
if(t<p)
stg=n;
}
n=n-n%5;
if(t==p)
fout<<n;
else
fout<<"-1";
return 0;
}
