Pagini recente » Cod sursa (job #2677723) | Cod sursa (job #377373) | Cod sursa (job #315017) | Cod sursa (job #298194) | Cod sursa (job #433578)
Cod sursa(job #433578)
#include<cstdio>
#include<fstream>
using namespace std;
unsigned long long rez=0,p;
int bun(unsigned long long x)
{
int cont=0;
unsigned long long putere=5,xx=x;
while(x>=putere)
{
cont+=(x/putere);
putere*=5;
}
if (cont>p) return 1;
else if ( cont == p )
{
rez = xx;
return 1;
}
return 0;
}
int main()
{
ifstream fin("fact.in");
//freopen("fact.out","w",stdout);
ofstream fout("fact.out");
fin>>p;
unsigned long long s=0,d=4200000000,m;
if(p==0) { fout<<1; return 0; }
else
while(s<=d)
{
m=(s+d)>>1;
if(bun(m))
{
d=m-1;
}
else s=m+1;
}
//printf("%lld\n",rez);
if(rez) fout<<rez;
else fout<<-1;
return 0;
}