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 integer number.

The following functions are provided by this module. All return values are computed exactly and are integers.

math.integer.comb(n, k, /)

n 個の中から k 個を重複無く順序をつけずに選ぶ方法の数を返します。

k <= n のとき n! / (k! * (n - k)!) と評価し、k > n のとき 0 と評価します。

これは (1 + x)ⁿ の多項式展開における第 k 項の係数と等しいので、二項係数とも呼ばれます。

Raises ValueError if either of the arguments are negative.

math.integer.factorial(n, /)

Return factorial of the nonnegative integer n.

math.integer.gcd(*integers)

指定された整数引数の最大公約数を返します。0 でない引数があれば、返される値は全ての引数の約数である最大の正の整数です。全ての引数が 0 なら、返される値は 0 です。引数の無い gcd() は 0 を返します。

math.integer.isqrt(n, /)

非負整数 n の整数平方根を返します。これは n の正確な平方根の床であり、 a² ≤ n を満たす最大の整数 a と等価です。

少し応用すれば、n ≤ a² を満たす最小の整数 a 、言い換えれば n の正確な平方根の天井を効率的に得られます。正の n に対して、これは a = 1 + isqrt(n - 1) を使って計算できます。

math.integer.lcm(*integers)

指定された整数引数の最小公倍数を返します。全ての引数が 0 でなければ、返される値は全ての引数の倍数である最小の正の整数です。引数に 0 があれば、返される値は 0 です。引数の無い lcm() は 1 を返します。

math.integer.perm(n, k=None, /)

n 個の中から k 個を重複無く順序をつけて選ぶ方法の数を返します。

k <= n のとき n! / (n - k)! と評価し、k > n のとき 0 と評価します。

If k is not specified or is None, then k defaults to n and the function returns n!.

Raises ValueError if either of the arguments are negative.