Pagini recente » Cod sursa (job #426398) | Cod sursa (job #551238) | Cod sursa (job #1618977) | Cod sursa (job #1999349) | Cod sursa (job #1196692)
#include <stdio.h>
using namespace std;
long long int p;
int main(){
long long int z=0, i=1, d=0,c=0,aux;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%lld", &p);
while (z<p)
{
aux=i;
while ((aux % 2) == 0){
d++;
aux/=2;
}
aux=i;
while ((aux % 5) == 0){
c++;
aux/=5;
}
if ((d) && (c)){
if (d>c) { d-=c; z+=c; c=0; }
else {c-=d; z+=d; d=0; }
}
i++;
}
if (p==0) printf("1");
else if (z==p) printf("%lld",i-1);
else printf("-1");
return 0;
}