Cod sursa(job #2199622)
Utilizator | VasileOctavian OctavianVasile | Data | 28 aprilie 2018 15:35:01 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.83 kb |
#include <fstream>
using namespace std;
ifstream cin ("fact.in") ;
ofstream cout ("fact.out") ;
long a , b , p , n , md , nr , x , put ;
int main()
{
cin >> p ;
if ( p==0 )
cout << 1 ;
else
{
a = 5 ;
b = 2000000000;
while ( a <= b )
{
md = ( a + b ) / 2 ;
x = 5 ;
n = md ;
put=0 ;
while ( n / x >= 1 )
{
put = put + n/x ;
x = x*5 ;
}
if ( put < p )
a = md+1;
else
{
if (put == p)
nr = md ;
b = md - 1 ;
}
}
if (nr != 0 )
cout << nr ;
else
cout << "-1" ;
}
return 0;
}