Cod sursa(job #542122)
| Utilizator | Data | 25 februarie 2011 20:11:22 | |
|---|---|---|---|
| Problema | Factorial | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.71 kb |
#include <stdio.h>
int fact (int n)
{
int i, a, b, c=0;
for (i=5; i<=n; i+=5) {
a=i;
b=0;
while (a%5==0) {
b++;
a/=5;
}
c+=b;
}
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;
}
