Pagini recente » Cod sursa (job #2137468) | Cod sursa (job #2611250) | Cod sursa (job #2671016) | Cod sursa (job #754829) | Cod sursa (job #471944)
Cod sursa(job #471944)
#include <fstream>
using namespace std;
unsigned long long calculeazaNrZero ( unsigned long long x )
{
unsigned long long nr = 0;
while ( x )
{
nr += x / 5 ;
x /= 5 ;
}
return nr;
}
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
int p, sw = 1;
unsigned long long a, b, c, nrZero;
fin >> p;
a = 1;
c = 490000000;
if ( p == 0 )
fout<< "1\n" ;
else
{
while(a <= c)
{
b = ( a + c ) / 2;
nrZero = calculeazaNrZero ( b ) ;
if( p == nrZero )
fout << b - b % 5 << '\n', sw = 0, c = a - 1;
else
if( nrZero > p )
c = b - 1;
else
a = b + 1;
}
if ( sw ) fout << "-1\n" ;
}
fout.close();
fin.close();
return 0;
}