Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c08163

Browse files
committed
fix some images and links
1 parent c4b203c commit 6c08163

File tree

72 files changed

+262
-262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+262
-262
lines changed

src/algebra/all-submasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Let's prove that the inner loop will execute a total of $O(3^n)$ iterations.
6060

6161
As there are a total of $n$ bits, there will be $3^n$ different combinations.
6262

63-
**Second proof**: Note that if mask $m$ has $k$ enabled bits, then it will have $2^k$ submasks. As we have a total of $\binom{n}{k}$ masks with $k$ enabled bits (see [binomial coefficients](./combinatorics/binomial-coefficients.html)), then the total number of combinations for all masks will be:
63+
**Second proof**: Note that if mask $m$ has $k$ enabled bits, then it will have $2^k$ submasks. As we have a total of $\binom{n}{k}$ masks with $k$ enabled bits (see [binomial coefficients](../combinatorics/binomial-coefficients.md)), then the total number of combinations for all masks will be:
6464

6565
$$\sum_{k=0}^n \binom{n}{k} \cdot 2^k$$
6666

src/algebra/big-integer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ This method is often used for calculations modulo non-prime number M; in this ca
162162

163163
The idea is to choose a set of prime numbers (typically they are small enough to fit into standard integer data type) and to store an integer as a vector of remainders from division of the integer by each of those primes.
164164

165-
Chinese remainder theorem states that this representation is sufficient to uniquely restore any number from 0 to product of these primes minus one. [Garner algorithm](./algebra/chinese-remainder-theorem.html) allows to restore the number from such representation to normal integer.
165+
Chinese remainder theorem states that this representation is sufficient to uniquely restore any number from 0 to product of these primes minus one. [Garner algorithm](chinese-remainder-theorem.md) allows to restore the number from such representation to normal integer.
166166

167-
This method allows to save memory compared to the classical approach (though the savings are not as dramatic as in factorization representation). Besides, it allows to perform fast addition, subtraction and multiplication in time proportional to the number of prime numbers used as modulos (see [Chinese remainder theorem](./algebra/chinese-remainder-theorem.html) article for implementation).
167+
This method allows to save memory compared to the classical approach (though the savings are not as dramatic as in factorization representation). Besides, it allows to perform fast addition, subtraction and multiplication in time proportional to the number of prime numbers used as modulos (see [Chinese remainder theorem](chinese-remainder-theorem.md) article for implementation).
168168

169169
The tradeoff is that converting the integer back to normal form is rather laborious and requires implementing classical arbitrary-precision arithmetic with multiplication. Besides, this method doesn't support division.
170170

src/algebra/binary-exp.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ long long binpow(long long a, long long b) {
8787

8888
**Problem:**
8989
Compute $x^n \bmod m$.
90-
This is a very common operation. For instance it is used in computing the [modular multiplicative inverse](./algebra/module-inverse.html).
90+
This is a very common operation. For instance it is used in computing the [modular multiplicative inverse](module-inverse.md).
9191

9292
**Solution:**
9393
Since we know that the module operator doesn't interfere with multiplications ($a \cdot b \equiv (a \bmod m) \cdot (b \bmod m) \pmod m$), we can directly use the same code, and just replace every multiplication with a modular multiplication:
@@ -107,13 +107,13 @@ long long binpow(long long a, long long b, long long m) {
107107
```
108108
109109
**Note:** If $m$ is a prime number we can speed up a bit this algorithm by calculating $x ^ {n \mod (m-1)}$ instead of $x ^ n$.
110-
This follows directly from [Fermat's little theorem](./algebra/module-inverse.html#toc-tgt-2).
110+
This follows directly from [Fermat's little theorem](module-inverse.md#toc-tgt-2).
111111
112112
### Effective computation of Fibonacci numbers
113113
114114
**Problem:** Compute $n$-th Fibonacci number $F_n$.
115115
116-
**Solution:** For more details, see the [Fibonacci Number article](./algebra/fibonacci-numbers.html).
116+
**Solution:** For more details, see the [Fibonacci Number article](fibonacci-numbers.md).
117117
We will only go through an overview of the algorithm.
118118
To compute the next Fibonacci number, only the two previous ones are needed, as $F_n = F_{n-1} + F_{n-2}$.
119119
We can build a $2 \times 2$ matrix that describes this transformation:
@@ -194,7 +194,7 @@ Now, once every transformation is described as a matrix, the sequence of transfo
194194
195195
**Problem:** Given a directed unweighted graph of $n$ vertices, find the number of paths of length $k$ from any vertex $u$ to any other vertex $v$.
196196
197-
**Solution:** This problem is considered in more detail in [a separate article](./graph/fixed_length_paths.html). The algorithm consists of raising the adjacency matrix $M$ of the graph (a matrix where $m_{ij} = 1$ if there is an edge from $i$ to $j$, or $0$ otherwise) to the $k$-th power. Now $m_{ij}$ will be the number of paths of length $k$ from $i$ to $j$. The time complexity of this solution is $O(n^3 \log k)$.
197+
**Solution:** This problem is considered in more detail in [a separate article](../graph/fixed_length_paths.md). The algorithm consists of raising the adjacency matrix $M$ of the graph (a matrix where $m_{ij} = 1$ if there is an edge from $i$ to $j$, or $0$ otherwise) to the $k$-th power. Now $m_{ij}$ will be the number of paths of length $k$ from $i$ to $j$. The time complexity of this solution is $O(n^3 \log k)$.
198198
199199
**Note:** In that same article, another variation of this problem is considered: when the edges are weighted and it is required to find the minimum weight path containing exactly $k$ edges. As shown in that article, this problem is also solved by exponentiation of the adjacency matrix. The matrix would have the weight of the edge from $i$ to $j$, or $\infty$ if there is no such edge.
200200
Instead of the usual operation of multiplying two matrices, a modified one should be used:

src/algebra/chinese-remainder-theorem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Let $r_{ij}$ denote the inverse of $p_i$ modulo $p_j$
4444
$$
4545
r_{ij} = (p_i)^{-1} \pmod{p_j}
4646
$$
47-
which can be found using the algorithm described in [Modular Inverse](./algebra/module-inverse.html). Substituting $a$ from the mixed radix representation into the first congruence equation we obtain
47+
which can be found using the algorithm described in [Modular Inverse](module-inverse.md). Substituting $a$ from the mixed radix representation into the first congruence equation we obtain
4848
$$
4949
a_1 \equiv x_1 \pmod{p_1}.
5050
$$

src/algebra/discrete-log.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ This problem can be solved using the meet-in-the-middle method as follows:
4343

4444
## Complexity
4545

46-
We can calculate $f_1(p)$ in $O(\log m)$ using the [binary exponentation algorithm](./algebra/binary-exp.html). Similarly for $f_2(q)$.
46+
We can calculate $f_1(p)$ in $O(\log m)$ using the [binary exponentation algorithm](binary-exp.md). Similarly for $f_2(q)$.
4747

4848
In the first step of the algorithm, we need to calculate $f_1$ for every possible argument $p$ and then sort the values. Thus, this step has complexity:
4949

@@ -125,7 +125,7 @@ With this change, the complexity of the algorithm is still the same, but now the
125125
Instead of a `map`, we can also use a hash table (`unordered_map` in C++) which has the average time complexity $O(1)$ for inserting and searching.
126126

127127
Problems often ask for the minimum $x$ which satisfies the solution.
128-
It is possible to get all answers and take the minimum, or reduce the first found answer using [Euler's theorem](./algebra/phi-function.html#toc-tgt-2), but we can be smart about the order in which we calculate values and ensure the first answer we find is the minimum.
128+
It is possible to get all answers and take the minimum, or reduce the first found answer using [Euler's theorem](phi-function.md#toc-tgt-2), but we can be smart about the order in which we calculate values and ensure the first answer we find is the minimum.
129129

130130
```cpp discrete_log
131131
// Returns minimum x for which a ^ x % m = b % m, a and m are coprime.

src/algebra/discrete-root.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ $x^k \equiv a \pmod n$
88

99
## The algorithm
1010

11-
We will solve this problem by reducing it to the [discrete logarithm problem](./algebra/discrete-log.html).
11+
We will solve this problem by reducing it to the [discrete logarithm problem](discrete-log.md).
1212

13-
Let's apply the concept of a [primitive root](./algebra/primitive-root.html) modulo $n$. Let $g$ be a primitive root modulo $n$. Note that since $n$ is prime, it must exist, and it can be found in $O(Ans \cdot \log \phi (n) \cdot \log n) = O(Ans \cdot \log^2 n)$ plus time of factoring $\phi (n)$.
13+
Let's apply the concept of a [primitive root](primitive-root.md) modulo $n$. Let $g$ be a primitive root modulo $n$. Note that since $n$ is prime, it must exist, and it can be found in $O(Ans \cdot \log \phi (n) \cdot \log n) = O(Ans \cdot \log^2 n)$ plus time of factoring $\phi (n)$.
1414

1515
We can easily discard the case where $a = 0$. In this case, obviously there is only one answer: $x = 0$.
1616

src/algebra/extended-euclid-algorithm.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!--?title Extended Euclidean Algorithm -->
22
# Extended Euclidean Algorithm
33

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](euclid-algorithm.md) 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:
55

66
$$a \cdot x + b \cdot y = \gcd(a, b)$$
77

88
It's important to note, that we can always find such a representation, for instance $\gcd(55, 80) = 5$ therefore we can represent $5$ as a linear combination with the terms $55$ and $80$: $55 \cdot 3 + 80 \cdot (-2) = 5$
99

10-
A more general form of that problem is discussed in the article about [Linear Diophantine Equations](algebra/linear-diophantine-equation.html).
10+
A more general form of that problem is discussed in the article about [Linear Diophantine Equations](linear-diophantine-equation.md).
1111
It will build upon this algorithm.
1212

1313
## Algorithm
@@ -88,7 +88,7 @@ int gcd(int a, int b, int& x, int& y) {
8888
}
8989
```
9090

91-
If you look closely at the variable `a1` and `b1`, you can notice that they taking exactly the same values as in the iterative version of the normal [Euclidean algorithm](algebra/euclid-algorithm.html). So the algorithm will at least compute the correct GCD.
91+
If you look closely at the variable `a1` and `b1`, you can notice that they taking exactly the same values as in the iterative version of the normal [Euclidean algorithm](euclid-algorithm.md). So the algorithm will at least compute the correct GCD.
9292

9393
To see why the algorithm also computes the correct coefficients, you can check that the following invariants will hold at any time (before the while loop, and at the end of each iteration): $x \cdot a + y \cdot b = a_1$ and $x_1 \cdot a + y_1 \cdot b = b_1$.
9494
It's trivial to see, that these two equations are satisfied at the beginning.

src/algebra/factorial-modulo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Imaging you write down the prime factorization of $n!$, remove all factors $p$,
1212
We will denote this *modified* factorial with $n!\_{\%p}$.
1313
For instance $7!_{\%p} \equiv 1 \cdot 2 \cdot \underbrace{1}\_{3} \cdot 4 \cdot 5 \underbrace{2}\_{6} \cdot 7 \equiv 2 \bmod 3$.
1414

15-
Learning how to effectively calculate this modified factorial allows us to quickly calculate the value of the various combinatorial formulas (for example, [Binomial coefficients](./combinatorics/binomial-coefficients.html)).
15+
Learning how to effectively calculate this modified factorial allows us to quickly calculate the value of the various combinatorial formulas (for example, [Binomial coefficients](../combinatorics/binomial-coefficients.md)).
1616

1717
## Algorithm
1818
Let's write this modified factorial explicitly.
@@ -35,7 +35,7 @@ The main part of the blocks it is easy to count — it's just $(p-1)!\ \mathrm{m
3535
We can compute that programmatically or just apply Wilson theorem which states that $(p-1)! \bmod p = -1$ for any prime $p$.
3636

3737
We have exactly $\lfloor \frac{n}{p} \rfloor$ such blocks, therefore we need to raise $-1$ to the power of $\lfloor \frac{n}{p} \rfloor$.
38-
This can be done in logarithmic time using [Binary Exponentiation](./algebra/binary-exp.html); however you can also notice that the result will switch between $-1$ and $1$, so we only need to look at the parity of the exponent and multiply by $-1$ if the parity is odd.
38+
This can be done in logarithmic time using [Binary Exponentiation](binary-exp.md); however you can also notice that the result will switch between $-1$ and $1$, so we only need to look at the parity of the exponent and multiply by $-1$ if the parity is odd.
3939
And instead of a multiplication, we can also just subtract the current result from $p$.
4040

4141
The value of the last partial block can be calculated separately in $O(p)$.

src/algebra/factorization.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
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 on their input.
55

66
Notice, if the number that you want to factorize is actually a prime number, most of the algorithms, especially Fermat's factorization algorithm, Pollard's p-1, Pollard's rho algorithm will run very slow.
7-
So it makes sense to perform a probabilistic (or a fast deterministic) [primality test](./algebra/primality_tests.html) before trying to factorize the number.
7+
So it makes sense to perform a probabilistic (or a fast deterministic) [primality test](primality_tests.md) before trying to factorize the number.
88

99
## Trial division
1010

@@ -103,7 +103,7 @@ However, also the skip lists will get a lot bigger.
103103
### Precomputed primes
104104
105105
Extending the wheel factorization with more and more primes will leave exactly the primes to check.
106-
So a good way of checking is just to precompute all prime numbers with the [Sieve of Eratosthenes](./algebra/sieve-of-eratosthenes.html) until $\sqrt{n}$ and test them individually.
106+
So a good way of checking is just to precompute all prime numbers with the [Sieve of Eratosthenes](sieve-of-eratosthenes.md) until $\sqrt{n}$ and test them individually.
107107
108108
```cpp factorization_trial_division4
109109
vector<long long> primes;
@@ -161,7 +161,7 @@ E.g. the prime factorization of $4817191$ is $1303 \cdot 3697$.
161161
And the factors are $31$-powersmooth and $16$-powersmooth respectably, because $1303 - 1 = 2 \cdot 3 \cdot 7 \cdot 31$ and $3697 - 1 = 2^4 \cdot 3 \cdot 7 \cdot 11$.
162162
In 1974 John Pollard invented a method to extracts $B$-powersmooth factors from a composite number.
163163
164-
The idea comes from [Fermat's little theorem](./algebra/phi-function.html#application).
164+
The idea comes from [Fermat's little theorem](phi-function.md#application).
165165
Let a factorization of $n$ be $n = p \cdot q$.
166166
It says that if $a$ is coprime to $p$, the following statement holds:
167167
@@ -174,7 +174,7 @@ $$a^{(p - 1)^k} \equiv a^{k \cdot (p - 1)} \equiv 1 \pmod{p}.$$
174174
So for any $M$ with $p - 1 ~|~ M$ we know that $a^M \equiv 1$.
175175
This means that $a^M - 1 = p \cdot r$, and because of that also $p ~|~ \gcd(a^M - 1, n)$.
176176
177-
Therefore, if $p - 1$ for a factor $p$ of $n$ divides $M$, we can extract a factor using [Euclid's algorithm](./algebra/euclid-algorithm.html).
177+
Therefore, if $p - 1$ for a factor $p$ of $n$ divides $M$, we can extract a factor using [Euclid's algorithm](euclid-algorithm.md).
178178
179179
It is clear, that the smallest $M$ that is a multiple of every $B$-powersmooth number is $\text{lcm}(1,~2~,3~,4~,~\dots,~B)$.
180180
Or alternatively:
@@ -240,7 +240,7 @@ If $p$ is smaller than $\sqrt{n}$, the repetition will start very likely in $O(\
240240
Here is a visualization of such a sequence $\{x_i \bmod p\}$ with $n = 2206637$, $p = 317$, $x_0 = 2$ and $f(x) = x^2 + 1$.
241241
From the form of the sequence you can see very clearly why the algorithm is called Pollard's $\rho$ algorithm.
242242

243-
<center>![Pollard's rho visualization](&imgroot&/pollard_rho.png)</center>
243+
<center>![Pollard's rho visualization](pollard_rho.png)</center>
244244

245245
There is still one big open question.
246246
We don't know $p$ yet, so how can we argue about the sequence $\{x_i \bmod p\}$?
@@ -328,7 +328,7 @@ i & x_i \bmod n & x_{2i} \bmod n & x_i \bmod 317 & x_{2i} \bmod 317 & \gcd(x_i -
328328
\end{array}$$
329329
330330
The implementation uses a function `mult`, that multiplies two integers $\le 10^{18}$ without overflow by using a GCC's type `__int128` for 128-bit integer.
331-
If GCC is not available, you can using a similar idea as [binary exponentiation](./algebra/binary-exp.html).
331+
If GCC is not available, you can using a similar idea as [binary exponentiation](binary-exp.md).
332332
333333
```cpp pollard_rho_mult2
334334
long long mult(long long a, long long b, long long mod) {
@@ -343,7 +343,7 @@ long long mult(long long a, long long b, long long mod) {
343343
}
344344
```
345345

346-
Alternatively you can also implement the [Montgomery multiplication](./algebra/montgomery_multiplication.html).
346+
Alternatively you can also implement the [Montgomery multiplication](montgomery_multiplication.md).
347347

348348
As already noticed above: if $n$ is composite and the algorithm returns $n$ as factor, you have to repeat the procedure with different parameter $x_0$ and $c$.
349349
E.g. the choice $x_0 = c = 1$ will not factor $25 = 5 \cdot 5$.

src/algebra/fft.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ Thus all the properties that we need from the complex roots are also available i
437437
For example we can take the following values: module $p = 7340033$, $w_{2^{20}} = 5$.
438438
If this module is not enough, we need to find a different pair.
439439
We can use that fact that for modules of the form $p = c 2^k + 1$ (and $p$ is prime), there always exists the $2^k$-th root of unity.
440-
It can be shown that $g^c$ is such a $2^k$-th root of unity, where $g$ is a [primitive root](./algebra/primitive-root.html) of $p$.
440+
It can be shown that $g^c$ is such a $2^k$-th root of unity, where $g$ is a [primitive root](primitive-root.md) of $p$.
441441

442442
```cpp fft_implementation_modular_arithmetic
443443
const int mod = 7340033;
@@ -482,7 +482,7 @@ void fft(vector<int> & a, bool invert) {
482482
}
483483
```
484484
485-
Here the function `inverse` computes the modular inverse (see [Modular Multiplicative Inverse](./algebra/module-inverse.html)).
485+
Here the function `inverse` computes the modular inverse (see [Modular Multiplicative Inverse](module-inverse.md)).
486486
The constants `mod`, `root`, `root_pw` determine the module and the root, and `root_1` is the inverse of `root` modulo `mod`.
487487
488488
In practice this implementation is slower than the implementation using complex numbers (due to the huge number of modulo operations), but it has some advantages such as less memory usage and no rounding errors.
@@ -494,7 +494,7 @@ Multiplying two polynomial $A(x)$ and $B(x)$, and computing the coefficients mod
494494
The number theoretic transform only works for certain prime numbers.
495495
What about the case when the modulus is not of the desired form?
496496
497-
One option would be to perform multiple number theoretic transforms with different prime numbers of the form $c 2^k + 1$, then apply the [Chinese Remainder Theorem](./algebra/chinese-remainder-theorem.html) to compute the final coefficients.
497+
One option would be to perform multiple number theoretic transforms with different prime numbers of the form $c 2^k + 1$, then apply the [Chinese Remainder Theorem](chinese-remainder-theorem.md) to compute the final coefficients.
498498
499499
Another options is to distribute the polynomials $A(x)$ and $B(x)$ into two smaller polynomials each
500500
$$\begin{align}

0 commit comments

Comments
 (0)