0% found this document useful (0 votes)
12 views2 pages

Public Documents 1

The document describes several number-theoretic functions in Python's math module, including math.comb, math.factorial, math.gcd, and math.isqrt. Each function has specific functionalities, such as calculating combinations, factorials, greatest common divisors, and integer square roots, along with their respective argument requirements and version changes. It highlights the importance of input types and conditions for proper function execution.

Uploaded by

tamoyskitv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Public Documents 1

The document describes several number-theoretic functions in Python's math module, including math.comb, math.factorial, math.gcd, and math.isqrt. Each function has specific functionalities, such as calculating combinations, factorials, greatest common divisors, and integer square roots, along with their respective argument requirements and version changes. It highlights the importance of input types and conditions for proper function execution.

Uploaded by

tamoyskitv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Number-theoretic functions

math.comb(n, k)

Return the number of ways to choose k items from n items without


repetition and without order.

Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates to


zero when k > n.

Also called the binomial coefficient because it is equivalent to the


coefficient of k-th term in polynomial expansion of (1 + x)ⁿ.

Raises TypeError if either of the arguments are not integers.


Raises ValueError if either of the arguments are negative.

Added in version 3.8.

math.factorial(n)

Return n factorial as an integer. Raises ValueError if n is not integral


or is negative.

Changed in version 3.10: Floats with integral values (like 5.0) are no
longer accepted.

math.gcd(*integers)

Return the greatest common divisor of the specified integer


arguments. If any of the arguments is nonzero, then the returned value
is the largest positive integer that is a divisor of all arguments. If all
arguments are zero, then the returned value is 0. gcd() without
arguments returns 0.

Added in version 3.5.

Changed in version 3.9: Added support for an arbitrary number of


arguments. Formerly, only two arguments were supported.

math.isqrt(n)

Return the integer square root of the nonnegative integer n. This is the
floor of the exact square root of n, or equivalently the greatest
integer a such that a² ≤ n.

For some applications, it may be more convenient to have the least


integer a such that n ≤ a², or in other words the ceiling of the exact
square root of n. For positive n, this can be computed
using a = 1 + isqrt(n - 1).

You might also like