Pagini recente » Cod sursa (job #1929817) | Cod sursa (job #739283) | Cod sursa (job #2745255) | Cod sursa (job #2807479) | Cod sursa (job #2623705)
#include <fstream>
using namespace std;
ofstream fout("fact.out");
ifstream fin("fact.in");
int p;
long long nr0;
int main()
{
fin>>p;
long long st = 1;
long long dr = 5e8;
while( st <= dr )
{
long long aux = ( st + dr ) / 2;
long long rez = 0;
while( aux >= 0 )
{
rez += ( aux / 5 ); /// n/5 + n/25 + n/125 + ...
aux /= 5;
}
if( rez >= p )
dr = ( st + dr ) / 2 - 1;
else
st = ( st + dr ) / 2 + 1;
}
long long aux = st;
long long rez = 0;
while( aux >= 5 )
{
rez += ( aux / 5 );
aux /= 5;
}
if( rez == p )
fout<<st;
else
fout<<-1;
}