Cod sursa(job #1368232)
| Utilizator | Data | 2 martie 2015 15:19:01 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | c | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#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;
}
