math.integer — integer-specific mathematics functions¶
Added in version 3.15.
This module provides access to the mathematical functions defined for integer arguments.These functions accept integers and objects that implement the__index__() method which is used to convert the object to an integernumber.
The following functions are provided by this module. All return values arecomputed exactly and are integers.
- math.integer.comb(n,k,/)¶
Return the number of ways to choosek items fromn items without repetitionand without order.
Evaluates to
n!/(k!*(n-k)!)whenk<=nand evaluatesto zero whenk>n.Also called the binomial coefficient because it is equivalentto the coefficient of k-th term in polynomial expansion of
(1+x)ⁿ.Raises
ValueErrorif either of the arguments are negative.
- math.integer.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 largestpositive integer that is a divisor of all arguments. If all argumentsare zero, then the returned value is
0.gcd()without argumentsreturns0.
- math.integer.isqrt(n,/)¶
Return the integer square root of the nonnegative integern. This is thefloor of the exact square root ofn, or equivalently the greatest integera such thata² ≤ n.
For some applications, it may be more convenient to have the least integera such thatn ≤ a², or in other words the ceiling ofthe exact square root ofn. For positiven, this can be computed using
a=1+isqrt(n-1).
- math.integer.lcm(*integers)¶
Return the least common multiple of the specified integer arguments.If all arguments are nonzero, then the returned value is the smallestpositive integer that is a multiple of all arguments. If any of the argumentsis zero, then the returned value is
0.lcm()without argumentsreturns1.
- math.integer.perm(n,k=None,/)¶
Return the number of ways to choosek items fromn itemswithout repetition and with order.
Evaluates to
n!/(n-k)!whenk<=nand evaluatesto zero whenk>n.Ifk is not specified or is
None, thenk defaults tonand the function returnsn!.Raises
ValueErrorif either of the arguments are negative.