Pagini recente » Istoria paginii runda/12334/clasament | Cod sursa (job #2117442) | Cod sursa (job #991096) | Cod sursa (job #700146) | Cod sursa (job #2616553)
#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 (m) == p )
return m;
else
return -1;
}
int main()
{
fin>> p ;
fout<< cautare_binara(1, 100000000);
}