Cod sursa(job #2404974)
| Utilizator | Data | 13 aprilie 2019 17:41:40 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int cif( int n )
{
int r = 0;
while( n >= 5 )
{
r += n/5;
n /= 5;
}
return r;
}
int cb( int n )
{
int r = 0, pas = 1 << 29;
while( pas != 0 )
{
if( cif( r + pas ) < n )
r += pas;
pas /= 2;
}
++r;
return r;
}
int main()
{
int n, m;
fin >> n;
m = cb(n);
if( cif(m) == n )
fout << m;
else
fout << -1;
return 0;
}
