Pagini recente » Cod sursa (job #876736) | Cod sursa (job #1465041) | Cod sursa (job #1191585) | Cod sursa (job #1300217) | Cod sursa (job #2616558)
#include <bits/stdc++.h>
using namespace std;
ifstream fin( "fact.in" );
ofstream fout( "fact.out" );
long long p;
int nr_zerouri_fact( int n )
{
int k = 5, s = 0;
while( k <= n )
{
s += n / k;
k *= 5;
}
return s;
}
int cautare_binara( int s, int d )
{
long long m;
int x;
while( s <= d )
{
m = ( s + d ) / 2;
x = nr_zerouri_fact (m);
if( x < p )
s = m + 1;
else d = m - 1;
}
if( nr_zerouri_fact (s) == p )
return s;
else
return -1;
}
int main()
{
fin>> p ;
fout<< cautare_binara(1, 1000000000);
}