Cod sursa(job #2616555)
| Utilizator | Data | 18 mai 2020 20:58:00 | |
|---|---|---|---|
| Problema | Factorial | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.67 kb |
#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, 100000000);
}
