Pagini recente » Cod sursa (job #485692) | Cod sursa (job #1063662) | Cod sursa (job #745587) | Cod sursa (job #2961201) | Cod sursa (job #542133)
Cod sursa(job #542133)
#include <stdio.h>
int pow5 (int x) {
int i, t=1;
for (i=1; i<=x; i++)
t*=5;
return t;
}
int fact (int n)
{
int k=1, c=0;
while (n/pow5(k)) {
c+=n/pow5(k);
k++;
}
return c;
}
int main ()
{
freopen("fact.in", "r", stdin);
freopen("fact.out", "w", stdout);
int p, st, dr, t;
scanf("%d", &p);
st=1;
dr=1000000;
while (st<=dr) {
t=(st+dr)/2;
if (p==fact(t)) {
while (p==fact(t)) {
t--;
}
printf ("%d", t+1);
break;
} else if (p<fact(t)) {
dr=t-1;
} else {
st=t+1;
}
}
return 0;
}