Pagini recente » Monitorul de evaluare | Clasament dupa rating | Istoria paginii utilizator/razvanguta | Profil SpiriFlaviu | Cod sursa (job #2103124)
#include <fstream>
#include <iostream>
#include <math.h>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int F(long long n)
{
int result=0;
long long exp=5;
while(n>=exp)
{
result+=n/exp;
exp*=5;
}
return result;
}
int main()
{
int N;
f>>N;
if(N==0) g<<1;
else
{
int64_t m,a=0,b=100000000;
bool found=0;
while(a+1<b && !found)
{
m=((a-b)>>1)+b;
if(F(m)<N) a=m+1;
else b=m-1;
//cout<<m<<" "<<F(m)<<endl;
if(F(m)==N) found=1;
}
if(found)
{
while(F(m)==N) m--; g<<m+1;
}
else g<<-1;
}
return 0;
}