Message408867
For the small cases (say n < 50), we can get faster code by using a small (3Kb) table of factorial logarithms:
double lf[50] = [log2(factorial(n)) for n in range(50)];
Then comb() and perm() function can be computed quickly and in constant time using the C99 math functions:
result = PyLong_FromDouble(round(exp2(lf[n] - (lf[r] + lf[n-r])))); |
|
Date |
User |
Action |
Args |
2021-12-18 20:40:55 | rhettinger | set | recipients:
+ rhettinger, tim.peters, mark.dickinson, serhiy.storchaka, PedanticHacker, mcognetta, Stefan Pochmann, pablogsal |
2021-12-18 20:40:55 | rhettinger | set | messageid: <1639860055.45.0.097167485904.issue37295@roundup.psfhosted.org> |
2021-12-18 20:40:55 | rhettinger | link | issue37295 messages |
2021-12-18 20:40:55 | rhettinger | create | |
|