Math¶
Greatest Common Divisor(GCD)¶
Greatest common divisor(GCD) of two positive integers is the largest positive integer that divides both numbers without remainder. It is useful for reducing fractions to be in its lowest terms.
1 2 3 4 5 6 |
|
Josephus Problem¶
People are standing in a circle wating to be executed. Counting begins at a special point in the circle and proceeds around the circle in a specified direction. After a specified number of people are skipped, the next person is executed. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only one person remains, and is freed.
We define that:
f(n, m)
returns the remaining people indexed from0
inn
people and skips eachm
people.- if we know
f(n - 1, m) = x
, then at then
trip we start from indexx + 1
and skipm
people and then return the answer:f(n - 1, m) + m
. Now that people are in a circle, we can avoid overflow byf(n, m) = (f(n - 1, m) + m) % n
. - As for the base, if
n == 1
, result is0
.
1 2 3 |
|
Probability¶
Conditional Probability¶
The conditional probability of an event \(A\), given an event \(B\) with \(P(B) > 0\), is defined by:
Multiplication Rule¶
Assuming that all of the conditioning events have positive probability, we have:
Total Probability Theorem¶
Let \(A_1, \cdots, A_n\) be disjoint events that form a partition of the sample space (each possible outcome is included in one and only one of the events \(A_1, \cdots, A_n\)) and assume that \(P(A_i) > 0\), for all \(i = 1, \cdots, n\). Then, for any event B, we have:
Bayes' Rule¶
Let \(A_1, A_2, \cdots, A_n\) be disjoint events that form a partition of the sample space, and assume that \(P(A_i) > 0\), for all \(i\). Then, for any event B such that \(P(B) > 0\), we have:
Counting¶
The permutation
of n objects is:
K-Permutations¶
If we want to count the number of different ways that we can pick k out of n objects and arrange them in a sequence, the number of posibble sequences is called k-permutations
:
K-Combinations¶
A combination is a choice of k elements out of an n-element set without regard to order. Combination has no ordering of the selected elements.
Partition¶
We have n distinct objects and we are given nonnegative integers \(n_1, n_2, \cdots, n_r\), whose sum is equal to n. The n items are to be divided into r disjoint groups, with the ith group containing exactly \(n_i\) items. Partitions of n objects into r groups with ith group having \(n_i\) objects is called multinomial coefficient
:
Expression¶
Addition¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Subtraction¶
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Multiplication¶
1 2 3 4 5 6 7 8 9 10 11 |
|
Division¶
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|