1 | initial version |
The following method avoids computing factorials explicitly, which can be computationally expensive for large values of n and r. Instead, it computes the product of a sequence of values using a generator expression, which is more memory-efficient and faster than computing factorials. You can compute perm(n, r) using a prod
function, which is a built-in SageMath function that computes the product of a sequence of values.
See the code:
perm(n, r) = prod(n - i for i in range(r))