Pagini recente » Cod sursa (job #345657) | Cod sursa (job #979450) | tema | Rating Gheorghita Stefan-Marian (Gheorghita) | Cod sursa (job #577916)
Cod sursa(job #577916)
#include <fstream>
using namespace std;
const char InFile[]="fact.in";
const char OutFile[]="fact.out";
const long long MaxN=1LL<<35;
ifstream fin(InFile);
ofstream fout(OutFile);
long long N,sol;
inline long long legendre(long long a,long long p)
{
long long p2=p;
long long sol=0;
while(p2<=a)
{
sol+=a/p2;
p2*=p;
}
return sol;
}
int main()
{
fin>>N;
fin.close();
long long step=1;
long long first=0;
for(;step<=MaxN;step<<=1);
for(;step;step>>=1)
{
long long index=first+step;
if(index<=MaxN)
{
long long x=legendre(index,5);
if(x<N)
{
first=index;
}
}
}
++first;
if(legendre(first,5)==N)
{
sol=first;
}
else
{
sol=-1;
}
fout<<sol;
fout.close();
return 0;
}