Pagini recente » Cod sursa (job #1889263) | Cod sursa (job #2625913) | Cod sursa (job #664644) | Cod sursa (job #1219244) | Cod sursa (job #1368232)
#include <stdio.h>
#include <stdlib.h>
long long legendre(long long n,long long x)
{
long long z=0,b;
b=x;
while(b<=n)
{
z+=(n/b);
b*=x;
}
return z;
}
int main()
{
long long p,i,pas,x;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%lld",&p);
i=0;
pas=1<<30;
while(pas!=0)
{
if(legendre(i+pas,5)<p)
i+=pas;
pas/=2;
}
if(legendre(i+1,5)==p)
printf("%d\n",i+1);
if(legendre(i+1,5)>p)
printf("%d\n",-1);
return 0;
}