Pagini recente » Cod sursa (job #2636864) | Cod sursa (job #1284121) | Cod sursa (job #1914232) | Cod sursa (job #213528) | Cod sursa (job #471943)
Cod sursa(job #471943)
#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;
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;
}