Pagini recente » Diferente pentru home intre reviziile 622 si 902 | Monitorul de evaluare | Monitorul de evaluare | Atasamentele paginii 2017 2017 2017 2017 2017 2017 2017 2017 | Cod sursa (job #1750897)
#include <cstdio>
using namespace std;
int n;
int p[]={5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, 48828125};
int main()
{
freopen("fact.in", "r", stdin);
freopen("fact.out", "w", stdout);
scanf("%d", &n);
if(n==0) {printf("1");return 0;}
int st=1,dr=100000000/5;
while(st<=dr){
int mij=(st+dr)/2;mij=mij*5;
long long j=0,legendre=0;
while(p[j]<=mij&&j<=10){legendre=legendre+(mij/p[j]);++j;}
mij=mij/5;
if(legendre==n){printf("%d",mij*5);return 0;}
else if(legendre<n) st=mij+1;
else dr=mij-1;
}printf("-1");
return 0;
}