Pagini recente » Profil mecipry | Istoria paginii utilizator/djok | Profil Anastasia11 | Cod sursa (job #1341353) | Cod sursa (job #163742)
Cod sursa(job #163742)
# include <iostream>
# include <fstream>
using namespace std ;
long long int pow5 ( long long int n ) {
long long int s = 0 ;
while ( 0 < n ) {
n = n / 5 ;
s += n ;
}
return s ;
}
int
main ( ) {
ifstream sin ( "fact.in" ) ;
ofstream sout ( "fact.out" ) ;
long long int a = 1 ;
long long int b = 0x7fffffffffffffffLL / 2LL;
long long int c ;
long long int p ;
sin >> p ;
bool found = false ;
while ( a <= b ) {
c = ( a + b ) / 2 ;
long long int d = pow5 ( c ) ;
if ( p < d ) {
b = -1 + c ;
} else if ( p > d ) {
a = + 1 + c ;
} else {
found = true ;
a = 1 + b ;
}
}
if ( found ) {
a = c - ( c % 5 ) ;
if ( 0 == a ) {
a = 1 ;
}
} else {
a = - 1 ;
}
sout << a << endl ;
return 0 ;
}