You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/algebra/extended-euclid-algorithm.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
<!--?title Extended Euclidean Algorithm -->
2
2
# Extended Euclidean Algorithm
3
3
4
-
While the [Euclidean algorithm](../algebra/euclid-algorithm.html) calculates only the greatest common divisor (GCD) of two integers $a$ and $b$, the extended version also finds a way to represent GCD in terms of $a$ and $b$, i.e. coefficients $x$ and $y$ for which:
4
+
While the [Euclidean algorithm](./algebra/euclid-algorithm.html) calculates only the greatest common divisor (GCD) of two integers $a$ and $b$, the extended version also finds a way to represent GCD in terms of $a$ and $b$, i.e. coefficients $x$ and $y$ for which:
Copy file name to clipboardExpand all lines: src/algebra/phi-function.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ The following properties of Euler totient function are sufficient to calculate i
23
23
24
24
- If $a$ and $b$ are relatively prime, then:
25
25
$$\phi(a b) = \phi(a) \cdot \phi(b).$$
26
-
This relation is not trivial to see. It follows from the [Chinese remainder theorem](../algebra/chinese-remainder-theorem.html). The Chinese remainder theorem guarantees, that for each $0 \le x < a$ and each $0 \le y < b$, there exists a unique $0 \le z < a b$ with $z \equiv x \pmod{a}$ and $z \equiv y \pmod{b}$. It's not hard to show that $z$ is coprime to $a b$ if and only if $x$ is coprime to $a$ and $y$ is coprime to $b$. Therefore the amount of integers coprime to $a b$ is equal to product of the amounts of $a$ and $b$.
26
+
This relation is not trivial to see. It follows from the [Chinese remainder theorem](./algebra/chinese-remainder-theorem.html). The Chinese remainder theorem guarantees, that for each $0 \le x < a$ and each $0 \le y < b$, there exists a unique $0 \le z < a b$ with $z \equiv x \pmod{a}$ and $z \equiv y \pmod{b}$. It's not hard to show that $z$ is coprime to $a b$ if and only if $x$ is coprime to $a$ and $y$ is coprime to $b$. Therefore the amount of integers coprime to $a b$ is equal to product of the amounts of $a$ and $b$.
27
27
28
28
- In general, for not coprime $a$ and $b$, the equation $$\phi(ab) = \phi(a) \cdot \phi(b) \cdot \dfrac{d}{\phi(d)}$$ with $d = \gcd(a, b)$ holds.
29
29
@@ -121,7 +121,7 @@ $$a^{\phi(m)} \equiv 1 \pmod m$$ if $a$ and $m$ are relatively prime.
121
121
In the particular case when $m$ is prime, Euler's theorem turns into **Fermat's little theorem**:
122
122
$$a^{m - 1} \equiv 1 \pmod m$$
123
123
124
-
Euler's theorem and Euler's totient function occur quite often in practical applications, for example both are used to compute the [modular multiplicative inverse](../algebra/module-inverse.html).
124
+
Euler's theorem and Euler's totient function occur quite often in practical applications, for example both are used to compute the [modular multiplicative inverse](./algebra/module-inverse.html).
125
125
126
126
As immediate consequence we also get the equivalence:
Copy file name to clipboardExpand all lines: src/algebra/primality_tests.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ Multiple such optimizations are described in the article about [integer factoriz
32
32
33
33
This is a probabilistic test.
34
34
35
-
Fermat's little theorem (see also [Euler's totient function](https://cp-algorithms.com/algebra/phi-function.html)) states, that for a prime number $p$ and a coprime integer $a$ the following equation holds:
35
+
Fermat's little theorem (see also [Euler's totient function](./algebra/phi-function.html)) states, that for a prime number $p$ and a coprime integer $a$ the following equation holds:
Copy file name to clipboardExpand all lines: src/sequences/rmq.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
You are given an array $A[1..N]$.
6
6
You have to answer incoming queries of the form $(L, R)$, which ask to find the minimum element in array $A$ between positions $L$ and $R$ inclusive.
7
7
8
-
RMQ can appear in problems directly or can be applied in some other tasks, e.g. the [Lowest Common Ancestor](../graph/lca.html) problem.
8
+
RMQ can appear in problems directly or can be applied in some other tasks, e.g. the [Lowest Common Ancestor](./graph/lca.html) problem.
9
9
10
10
## Solution
11
11
@@ -15,20 +15,20 @@ The ones that are explained on this site are listed below.
15
15
16
16
First the approaches that allow modifications to the array between answering queries.
17
17
18
-
-[Sqrt-decomposition](../data_structures/sqrt_decomposition.html) - answers each query in $O(\sqrt{N})$, preprocessing done in $O(N)$.
18
+
-[Sqrt-decomposition](./data_structures/sqrt_decomposition.html) - answers each query in $O(\sqrt{N})$, preprocessing done in $O(N)$.
19
19
Pros: a very simple data structure. Cons: worse complexity.
20
-
-[Segment tree](../data_structures/segment_tree.html) - answers each query in $O(\log N)$, preprocessing done in $O(N)$.
20
+
-[Segment tree](./data_structures/segment_tree.html) - answers each query in $O(\log N)$, preprocessing done in $O(N)$.
21
21
Pros: good time complexity. Cons: larger amount of code compared to the other data structures.
22
-
-[Fenwick tree](../data_structures/fenwick.html) - answers each query in $O(\log N)$, preprocessing done in $O(N \log N)$.
22
+
-[Fenwick tree](./data_structures/fenwick.html) - answers each query in $O(\log N)$, preprocessing done in $O(N \log N)$.
23
23
Pros: the shortest code, good time complexity. Cons: Fenwick tree can only be used for queries with $L = 1$, so it is not applicable to many problems.
24
24
25
25
And here are the approaches that only work on static arrays, i.e. it is not possible to change a value in the array without recomputing the complete data structure.
26
26
27
-
-[Sparse Table](../data_structures/sparse-table.html) - answers each query in $O(1)$, preprocessing done in $O(N \log N)$.
27
+
-[Sparse Table](./data_structures/sparse-table.html) - answers each query in $O(1)$, preprocessing done in $O(N \log N)$.
28
28
Pros: simple data structure, excellent time complexity.
29
-
-[Sqrt Tree](../data_structures/sqrt-tree.html) - answers queries in $O(1)$, preprocessing done in $O(N \log \log N)$. Pros: fast. Cons: Complicated to implement.
30
-
-[Disjoint Set Union / Arpa's Trick](../data_structures/disjoint_set_union.html#arpa) - answers queries in $O(1)$, preprocessing in $O(n)$. Pros: short, fast. Cons: only works if all queries are known in advance, i.e. only supports off-line processing of the queries.
31
-
-[Cartesian Tree](../graph/rmq_linear.html) and [Farach-Colton and Bender algorithm](../graph/lca_farachcoltonbender.html) - answers queries in $O(1)$, preprocessing in $O(n)$. Pros: optimal complexity. Cons: large amount of code.
29
+
-[Sqrt Tree](./data_structures/sqrt-tree.html) - answers queries in $O(1)$, preprocessing done in $O(N \log \log N)$. Pros: fast. Cons: Complicated to implement.
30
+
-[Disjoint Set Union / Arpa's Trick](./data_structures/disjoint_set_union.html#arpa) - answers queries in $O(1)$, preprocessing in $O(n)$. Pros: short, fast. Cons: only works if all queries are known in advance, i.e. only supports off-line processing of the queries.
31
+
-[Cartesian Tree](./graph/rmq_linear.html) and [Farach-Colton and Bender algorithm](./graph/lca_farachcoltonbender.html) - answers queries in $O(1)$, preprocessing in $O(n)$. Pros: optimal complexity. Cons: large amount of code.
32
32
33
33
Note: Preprocessing is the preliminary processing of the given array by building the corresponding data structure for it.
0 commit comments