Pagini recente » Cod sursa (job #933095) | Cod sursa (job #1958028) | Cod sursa (job #1707552) | Cod sursa (job #345558) | Cod sursa (job #1257193)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int nr0(int z)
{
int cnt = 0;
while( z >= 5 )
{
cnt += z/5;
z /= 5;
}
return cnt;
}
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
unsigned long long p;
fin>>p;
if(p==0){fout<<1;return 0;}
long long x = 100000000000000000/2,n=0;
long mi=1,ma=x*2;
while(mi<=ma)
{
x=(mi+ma)/2;
if(nr0(x)==p)
{
n=x;
break;
}
else if(nr0(x)<p)
mi=x+1;
else
ma=x-1;
}
if(n!=0)
{
while(n>0 && nr0(n)==p)
n--;
fout<<n+1;
}
else
fout<<-1;
}