Skip to content
Sean Raven edited this page Oct 28, 2015 · 1 revision

Mathematics

Prime Numbers

A number N is prime if its only divisors are 1 and N.

A number N can be determined to be prime using the following:

  • If N is even, it is not prime (unless it is 2).
  • If N is odd, attempt to divide it by every odd number in [3, sqrt(N)]. If it is divisible by any such number, it is not prime.
    • A slight improvement is to divide N by every prime number in [3, sqrt(N)]. This requres an existing list of prime numbers.

Sieve of Eratosthenes

The Sieve of Eratosthenes is used to generate a list of prime numbers less than N.

Start by considering all numbers in [2, N] to be possibly prime. Then, for each number n in the list, mark n as prime and remove all multiples of n, starting with n * n.

Prime Factorization

A naive approach to find the prime factors of N is to generate a list of prime numbers smaller than N and check which ones divide N, without modifying N. A faster approach is to divide N by its smallest prime factor, then find the prime factors of the quotient.

Greatest Common Divisor (GCD) & Least Common Multiple (LCM)

Two numbers are relatively prime if their GCD is 1.

The Phi function is used to calculate how many numbers less than N are relatively prime to N. It is expressed as:

phi(N) = N * product( 1-(1/pf) for pf in prime_factors(N) )

Extended Euclid: Solving Linear Diophantine Equation

Fibonacci Numbers

Factorial

Java's BigInteger Class

Combinatorics deals with counting the number of ways something can be done.

Existing (or Fictional) Sequences and Number Systems

These are generally ad-hoc.

Other

Clone this wiki locally