HEX
Server: Apache
System: Linux beluga.o2switch.net 4.18.0-553.123.2.lve.el8.x86_64 #1 SMP Thu May 7 23:17:13 UTC 2026 x86_64
User: sc3naki1272 (1113)
PHP: 8.3.33
Disabled: NONE
Upload Files
File: //opt/alt/python37/share/doc/alt-python37-Cython/Demos/freeze/combinatorics.pyx
# cython: language_level=3

import lcmath


def nCr(n, r):
    """Return the number of ways to choose r elements of a set of n."""
    return lcmath.exp(
        lcmath.lfactorial(n) -
        lcmath.lfactorial(r) -
        lcmath.lfactorial(n-r)
    )

if __name__ == "__main__":
    import sys
    if len(sys.argv) != 3:
        sys.stderr.write("USAGE: %s n r\nPrints n-choose-r.\n" % sys.argv[0])
        sys.exit(2)
    n, r = map(float, sys.argv[1:])
    print(nCr(n, r))