Pagini recente » Cod sursa (job #446209) | Cod sursa (job #1321001) | Cod sursa (job #346215) | Cod sursa (job #2622902) | Cod sursa (job #1905169)
#include <cstdio>
using namespace std;
int n, P, p, u, m, nr, ok;
int zero (int m)
{
int fact=5, nr=0;
while (fact<=m){
nr+=m/fact;
fact*=5;
}
return nr;
}
int main (){
freopen("fact.in", "r", stdin);
freopen("fact.out", "w", stdout);
scanf("%d", &P);
if (P==0) printf("1");
else{
p=1;
u=5*P;
while (p<=u){
m=p+(u-p)/2;
nr=zero(m);
if (nr>=P) u=m-1;
else p=m+1;
if (nr==P) ok=1;
}
if (ok) printf("%d", p);
else printf("-1");
}
return 0;
}