The algorithm is based on the formula:
Binomial( n, k ) = n! / ( k! (n-k)! )
We determine whether k or (n - k) is larger, and use the larger value to cancel the numerator. This should lead to a minimum number of multiplications.
Name | Type | Description |
---|---|---|
Value | T * | Pointer to the result. |
size_t | n | |
size_t | k |
#include <nttl/binomial.h> ... long b; Binomial( &b, 5, 2 ); cout << "(5,2) = " << b << endl; |