Pagini recente » Cod sursa (job #1871262) | Cod sursa (job #1453616) | Cod sursa (job #1431354) | Cod sursa (job #1879789)
#include <fstream>
using namespace std ;
ifstream cin ("fact.in") ;
ofstream cout ("fact.out") ;
long long NrZero (long long x) {
long long S = 0 ;
while ( x / 5LL ) {
S = S + (x / 5LL) ;
x = x / 5LL ;
}
return S ;
}
int main()
{
long long P ;
cin >> P ;
long long st = 1 ;
long long dr = 2e9 ;
long long found = -1 ;
while ( st <= dr ){
long long mij = (st + dr) >> 1LL ;
if (NrZero(mij) >= P) {
dr = mij - 1 ;
found = mij ;
}
else {
st = mij + 1 ;
}
}
if (found == -1 or NrZero(found) != P) {
cout << -1 << '\n' ;
}
else {
if ( found - found % 5 == 0 ) {
cout << 1 << '\n' ;
return 0 ;
}
cout << found - found % 5 << '\n' ;
}
return 0 ;
}