Pagini recente » Cod sursa (job #2177265) | Cod sursa (job #366399) | Cod sursa (job #1202105) | Rating salut543 (salut543) | Cod sursa (job #1981553)
#include <stdio.h>
#include <stdlib.h>
int legendre(int x)
{
int p5=5,nr=0;
while(p5<=x)
{
nr+=(x/p5);
p5*=5;
}
return nr;
}
int cautbin(int p)
{
int i=0,pas=1<<30;
while(pas)
{
if(legendre(i+pas)<p)
i+=pas;
pas/=2;
}
if(legendre(i+1)==p) return i+1;
else return -1;
}
int main()
{
int p;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
printf("%d\n",cautbin(p));
return 0;
}