Pagini recente » Istoria paginii runda/caress/clasament | Atasamentele paginii problemebarajgimnaziu | Istoria paginii runda/tyy/clasament | Cod sursa (job #1208642) | Cod sursa (job #23772)
Cod sursa(job #23772)
#include<fstream.h>
ifstream fin("fact.in");
ofstream fout("fact.out");
unsigned long long int n, p, m, li, ls, med, gasit;
int main()
{
fin >> p;
li = 1, ls = 2000000000;
gasit = 0;
while ( li <= ls && !gasit )
{
med = ( li + ls ) / 2;
n = med;
m = 0;
while ( n != 0 )
{
m += n/5;
n /= 5;
}
if ( m == p ) gasit = med;
else if ( m < p ) li = med + 1;
else ls = med - 1;
}
if ( !gasit ) fout << -1 << endl;
else
{
if ( p == 0 ) fout << 1 << endl;
else fout << gasit - gasit%5 << endl;
}
fin.close();
fout.close();
return 0;
}