Cod sursa(job #1397531)
| Utilizator | Data | 23 martie 2015 16:31:09 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.68 kb |
#include <fstream>
#include <math.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
unsigned long p, gasok, li=0,ls=2000000000,mijd, m, n;
int main()
{
fin >> p;
if( p==0 )
{
fout <<"1"<<endl;
return 0;
}
while( li <= ls && !gasok )
{
mijd = li / 2 + ls / 2;
n = mijd;
m=0;
while( n != 0 )
{
m += n / 5;
n /= 5;
}
if( m == p ) gasok = mijd;
else if( m < p )
li = mijd + 1;
else ls = mijd - 1;
}
if (!gasok) fout<<"-1"<<endl;
else
fout<<gasok-gasok%5<<endl;
return 0;
}
