Arbitrary-Precision Arithmetic

2021 VietMX 0

Arbitrary-Precision arithmetic, also known as “bignum” or simply “long arithmetic” is a set of data structures and algorithms which allows to process much greater numbers […]

Submask Enumeration

2021 VietMX 0

1. Enumerating all submasks of a given mask Given a bitmask $m$, you want to efficiently iterate through all of its submasks, that is, masks […]

Gray code

2021 VietMX 506

Gray code is a binary numeral system where two successive values differ in only one bit. For example, the sequence of Gray codes for 3-bit […]

Balanced Ternary

2021 VietMX 0

1. Overview This is a non-standard but still positional numeral system. Its feature is that digits can have one of the values -1, 0 and […]

Montgomery Multiplication

2021 VietMX 0

Many algorithms in number theory, like prime testing or integer factorization, and in cryptography, like RSA, require lots of operations modulo a large number. A multiplications like $x […]

Discrete Root

2021 VietMX 0

The problem of finding a discrete root is defined as follows. Given a prime $n$ and two integers $a$ and $k$, find all $x$ for […]

Primitive Root

2021 VietMX 2

1. Definition In modular arithmetic, a number $g$ is called a primitive root modulo n if every number coprime to $n$ is congruent to a […]

Discrete Logarithm

2021 VietMX 0

The discrete logarithm is an integer $x$ satisfying the equation $$a^x \equiv b \pmod m$$ for given integers $a$, $b$ and $m$. The discrete logarithm […]

Factorial modulo $p$

2021 VietMX 1

In some cases it is necessary to consider complex formulas modulo some prime $p$, containing factorials in both numerator and denominator, like such that you […]

Euler’s totient function

2021 VietMX 0

Euler’s totient function, also known as phi-function $\phi (n)$, counts the number of integers between 1 and $n$ inclusive, which are coprime to $n$. Two numbers are […]

Integer factorization

2021 VietMX 1

In this article we list several algorithms for factorizing integers, each of them can be both fast and also slow (some slower than others) depending […]

Primality tests

2021 VietMX 2

This article describes multiple algorithms to determine if a number is prime or not. 1. Trial division By definition a prime number doesn’t have any […]

Sieve of Eratosthenes

2021 VietMX 2

Sieve of Eratosthenes is an algorithm for finding all the prime numbers in a segment $[1;n]$ using $O(n \log \log n)$ operations. The algorithm is […]

Fibonacci Numbers

2021 VietMX 0

The Fibonacci sequence is defined as follows: $$F_0 = 0, F_1 = 1, F_n = F_{n-1} + F_{n-2}$$ The first elements of the sequence (OEIS […]