An imos method can be implemented as the result of repeating the operation "add a certain number v to a certain continuous interval" K times in a 1-dimensional array of length N.
A binary search is an algorithm to find a particular element in the list. Suppose we have a list of thousand elements, and we need to get an index position of a particular element. We can find the element's index position very fast using the binary search algorithm.
>>> arr = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
>>> target = 64
>>> binary_search(-1, len(arr), lambda x: arr[x] >= target)
6
Computes nonnegative integer greatest common divisor.
>>> igcd(8, 9)
1
>>> igcd(30, 12)
6
Computes integer least common multiple.
>>> ilcm(2, 3)
6
>>> ilcm(123, 456)
18696
Chinese Remainder Theorem.
>>> crt([783, 278], [151, 57])
(31471, 217674)
>>> crt([12, 6, 17], [3, 4, 2])
(-1, 0)
Return a sorted list of n's prime factors.
>>> primefactors(42)
[2, 3, 7]
>>> primefactors(72)
[2, 2, 2, 3, 3]
Test if n is a prime number (True) or not (False).
>>> isprime(1)
False
>>> isprime(73)
True
>>> isprime(-1)
False
Return all divisors of n sorted from 1..n.
>>> divisors(4)
[1, 2, 4]
>>> divisors(12)
[1, 2, 3, 4, 6, 12]
An inverse permutation is a permutation in which each number and the number of the place which it occupies are exchanged.
>>> rperm([2, 3, 1])
[3, 1, 2]
>>> rperm([5, 3, 2, 4, 1])
[5, 3, 2, 4, 1]
Converts a string representation of a number in a given base into a decimal number.
>>> decimal("123", 8)
83
>>> decimal("1234", 10)
1234
Converts a number into a string representation with the given base (radix).
>>> base(11, 2)
'1011'
>>> base(1010101, 10)
'1010101'