Skip to content

Suffix dev #1502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 96 commits into
base: cpp-tips
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
1708451
Added Simulated Annealing
Proxihox Oct 18, 2024
1eb4b14
Formatting
Proxihox Oct 19, 2024
ebd3cdf
fixed compile issue
Proxihox Oct 19, 2024
9c81f79
Elaborated temp
Proxihox Oct 21, 2024
1962436
updated code
Proxihox Oct 29, 2024
7b46a26
fixed braces error
Proxihox Oct 29, 2024
e08ab50
Merge branch 'cp-algorithms:main' into main
Proxihox Oct 29, 2024
8ecb688
Merge branch 'main' of https://github.com/Proxihox/cp-algorithms into…
Proxihox Oct 29, 2024
d6f6b6a
Merge branch 'cp-algorithms:main' into main
Proxihox Nov 5, 2024
bab84cd
fixes
Proxihox Nov 5, 2024
31ec7e8
Merge branch 'main' into main
Proxihox Nov 10, 2024
304641c
Merge branch 'main' into main
Proxihox Dec 1, 2024
95e25cc
Merge branch 'main' into main
Proxihox Dec 24, 2024
a3db1b2
Merge branch 'cp-algorithms:main' into main
Proxihox Jan 27, 2025
dfc5b3e
Merge branch 'cp-algorithms:main' into main
Proxihox Feb 4, 2025
7c1254b
Empty commit for GitHub Actions
adamant-pwn Mar 24, 2025
9b8c5b6
Close <center> tag
adamant-pwn Mar 24, 2025
4d6b7b7
Merge branch 'main' into main
Proxihox Mar 30, 2025
fc498bc
Merge branch 'main' into main
mhayter Apr 15, 2025
a990b25
Merge branch 'main' into main
mhayter Apr 16, 2025
4cdc4df
Fibonacci: better motivation for matrix form
jxu Apr 17, 2025
7520d3e
Fibonacci: Cassini's identity proof sketches
jxu Apr 17, 2025
dddcce3
Merge branch 'cp-algorithms:main' into main
Proxihox Apr 18, 2025
375ca6b
log n -> \log n
adamant-pwn Apr 18, 2025
79d767c
Merge pull request #1453 from cp-algorithms/fibmatrix
adamant-pwn Apr 18, 2025
8c5bc69
m -> n in Aho-Corasick
adamant-pwn Apr 18, 2025
115cc22
Fibonacci: restore matrix power form
jxu Apr 19, 2025
59c3174
Update src/algebra/fibonacci-numbers.md
adamant-pwn Apr 19, 2025
06d6a83
Update fibonacci-numbers.md
mhayter Apr 22, 2025
f46c3c9
Merge pull request #1454 from cp-algorithms/cassini
mhayter Apr 22, 2025
3de210a
updated script to account for when text follows center tag
mhayter Apr 22, 2025
9f5502a
change 2 images rather than image then text
mhayter Apr 22, 2025
fc8d5dc
formatted multiple images in center tag
mhayter Apr 22, 2025
f46a230
double images not working in edmonds karp
mhayter Apr 22, 2025
51d3953
Merge pull request #1456 from mhayter/update_all_center_tag
mhayter Apr 22, 2025
546ce11
Merge pull request #1455 from cp-algorithms/fibmatrix
mhayter Apr 22, 2025
4bb7a0d
Merge branch 'cp-algorithms:main' into main
Proxihox Apr 26, 2025
bee2358
final fixes
Proxihox May 1, 2025
bdee148
Merge branch 'main' of https://github.com/Proxihox/cp-algorithms
Proxihox May 1, 2025
46e4efa
Typo fix in graph/fixed_length_paths.md
bit-shashank May 2, 2025
e8b714d
Merge pull request #1458 from bit-shashank/bit-shashank-patch-1
mhayter May 2, 2025
4611aee
Update CONTRIBUTING.md
mhayter May 7, 2025
27e90b5
Update factorization.md [Update Powersmooth Definition]
t0wbo2t May 15, 2025
63668dd
Merge branch 'cp-algorithms:main' into main
Proxihox May 19, 2025
6ec2fe6
Update longest_increasing_subsequence.md
100daysummer May 21, 2025
1471f1b
Merge pull request #1459 from cp-algorithms/mhayter-patch-2
adamant-pwn May 21, 2025
a29c713
Merge pull request #1463 from 100daysummer/patch-1
adamant-pwn May 21, 2025
d1cfad2
semicolon after e
adamant-pwn May 21, 2025
a82cd12
update date
adamant-pwn May 21, 2025
6eecd4a
Merge pull request #1371 from Proxihox/main
adamant-pwn May 21, 2025
422fb19
Update factorization.md [Update powersmooth definition with suggestions]
t0wbo2t May 21, 2025
1a7db31
Update factorization.md [Update Pollard's (p - 1) Method]
t0wbo2t May 22, 2025
bb7e137
fix #1372
adamant-pwn May 24, 2025
997afa0
Merge branch 'main' into patch-1
t0wbo2t May 29, 2025
2597e05
Update src/algebra/factorization.md
t0wbo2t May 29, 2025
54fec62
Update src/algebra/factorization.md
t0wbo2t May 29, 2025
53639d5
Update src/algebra/factorization.md
t0wbo2t May 29, 2025
3491526
Merge pull request #1461 from t0wbo2t/patch-1
adamant-pwn May 29, 2025
ecf52f7
Update stack_queue_modification.md
Tushar0009 May 31, 2025
cee3e33
Update fixed_length_paths.md
This-is-Adroit Jun 8, 2025
6befd12
Merge pull request #1466 from Tushar0009/patch-1
mhayter Jun 8, 2025
9c49a33
Merge branch 'cp-algorithms:main' into patch-1
This-is-Adroit Jun 9, 2025
06625c2
Update src/graph/fixed_length_paths.md
adamant-pwn Jun 14, 2025
0da3b79
Merge pull request #1468 from This-is-Adroit/patch-1
adamant-pwn Jun 14, 2025
77381f8
fix typo
aleksmish Jun 30, 2025
f28d1a2
Merge pull request #1474 from aleksmish/patch-1
mhayter Jul 1, 2025
7c3273f
Update treap.md
yousvf Jul 3, 2025
02bde94
Merge pull request #1477 from yousvf/patch-1
mhayter Jul 3, 2025
8869301
Grammatical Error Removed
ayushkrtiwari Jul 12, 2025
3abb392
Patch fix in Manhattan Distance.
Jul 12, 2025
f171f28
Merge pull request #1480 from ayushkrtiwari/main
mhayter Jul 18, 2025
55e4d52
docs: fix bridge count wording to “one or more” in bridge-searching-o…
abanoubashraf686 Jul 26, 2025
b455f1c
Fix grammar in binary-exp.md
arjunUpatel Jul 27, 2025
410ce4b
Update chinese-remainder-theorem.md
mlatysh199 Jul 29, 2025
276b929
Update linear-system-gauss.md
yousvf Jul 31, 2025
9176ebc
Merge pull request #1486 from arjunUpatel/patch-2
mhayter Aug 1, 2025
31ac655
Merge pull request #1487 from mlatysh199/patch-1
mhayter Aug 1, 2025
de89f25
Merge pull request #1488 from yousvf/patch-2
mhayter Aug 1, 2025
7492537
Merge pull request #1481 from kartik-laheri/CPA-1476-patch-in-manhatt…
mhayter Aug 1, 2025
9c7b6a6
Update polynomial.md
Gemefoll Aug 7, 2025
61dd11e
Add links to the Discord server (#1493)
adamant-pwn Aug 8, 2025
577bc74
Merge pull request #1491 from Gemefoll/main
mhayter Aug 8, 2025
6bc8214
Fix formula for r*a = C solution (#1479)
syed0369 Aug 9, 2025
e8e3022
Fix grammar: add missing 'is' in website text (#1482)
DeepankTyagi2001 Aug 9, 2025
742db16
Update manhattan-distance.md (#1490)
Shoot Aug 11, 2025
8668f0a
Fix grammar error in linear-diophantine-equation.md
arjunUpatel Aug 15, 2025
3a93e16
Merge pull request #1496 from arjunUpatel/patch-3
mhayter Aug 16, 2025
50bb121
Additional Problems on Burnside Lemma
ayushkrtiwari Aug 17, 2025
8f8fbbc
updated problem link
ayushkrtiwari Aug 17, 2025
2eed507
Merge pull request #1485 from abanoubashraf686/patch-1
spike1236 Aug 17, 2025
b453603
Merge pull request #1497 from ayushkrtiwari/main
Kostero Aug 18, 2025
ed33505
Add minimum enclosing circle article (#1498)
adamant-pwn Aug 19, 2025
878f8b4
touch commit for gh.cp-algorithms.com
adamant-pwn Aug 19, 2025
d2fa0f4
fix link to phi-function.md
adamant-pwn Aug 19, 2025
f00c1b4
Fix hyperlink in image description
adamant-pwn Aug 19, 2025
a0f92b2
Solicit donations on the website (#1499)
adamant-pwn Aug 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Follow these steps to start contributing:
4. **Preview your changes** using the [preview page](preview.md) to ensure they look correct.
5. **Commit your changes** by clicking the _Propose changes_ button.
6. **Create a Pull Request (PR)** by clicking _Compare & pull request_.
7. **Review process**: Someone from the core team will review your changes. This may take a few hours to a few days.
7. **Review process**: Someone from the core team will review your changes. This may take a few days to a few weeks.

### Making Larger Changes

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Compiled pages are published at [https://cp-algorithms.com/](https://cp-algorith

## Changelog

- August, 2025: Overhaul of CP-Algorithms [donation system](https://github.com/sponsors/cp-algorithms). Please consider supporting us, so that we can grow!
- August, 2025: Launched a [Discord server](https://discord.gg/HZ5AecN3KX)!
- October, 2024: Welcome new maintainers: [jxu](https://github.com/jxu), [mhayter](https://github.com/mhayter) and [kostero](https://github.com/kostero)!
- October, 15, 2024: GitHub pages based mirror is now served at [https://gh.cp-algorithms.com/](https://gh.cp-algorithms.com/), and an auxiliary competitive programming library is available at [https://lib.cp-algorithms.com/](https://lib.cp-algorithms.com/).
- July 16, 2024: Major overhaul of the [Finding strongly connected components / Building condensation graph](https://cp-algorithms.com/graph/strongly-connected-components.html) article.
Expand All @@ -29,6 +31,8 @@ Compiled pages are published at [https://cp-algorithms.com/](https://cp-algorith

### New articles

- (19 August 2025) [Minimum Enclosing Circle](https://cp-algorithms.com/geometry/enclosing-circle.html)
- (21 May 2025) [Simulated Annealing](https://cp-algorithms.com/num_methods/simulated_annealing.html)
- (12 July 2024) [Manhattan distance](https://cp-algorithms.com/geometry/manhattan-distance.html)
- (8 June 2024) [Knapsack Problem](https://cp-algorithms.com/dynamic_programming/knapsack.html)
- (28 January 2024) [Introduction to Dynamic Programming](https://cp-algorithms.com/dynamic_programming/intro-to-dp.html)
Expand Down
8 changes: 8 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ edit_uri: edit/main/src/
copyright: Text is available under the <a href="https://github.com/cp-algorithms/cp-algorithms/blob/main/LICENSE">Creative Commons Attribution Share Alike 4.0 International</a> License<br/>Copyright &copy; 2014 - 2025 by <a href="https://github.com/cp-algorithms/cp-algorithms/graphs/contributors">cp-algorithms contributors</a>
extra_javascript:
- javascript/config.js
- javascript/donation-banner.js
- https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=es6
- https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js
extra_css:
Expand Down Expand Up @@ -79,6 +80,13 @@ plugins:
- rss

extra:
social:
- icon: fontawesome/brands/github
link: https://github.com/cp-algorithms/cp-algorithms
- icon: fontawesome/brands/discord
link: https://discord.gg/HZ5AecN3KX
- icon: fontawesome/solid/circle-dollar-to-slot
link: https://github.com/sponsors/cp-algorithms
analytics:
provider: google
property: G-7FLS2HCYHH
2 changes: 1 addition & 1 deletion src/algebra/big-integer.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ To improve performance we'll use $10^9$ as the base, so that each "digit" of the
const int base = 1000*1000*1000;
```

Digits will be stored in order from least to most significant. All operations will be implemented so that after each of them the result doesn't have any leading zeros, as long as operands didn't have any leading zeros either. All operations which might result in a number with leading zeros should be followed by code which removes them. Note that in this representation there are two valid notations for number zero: and empty vector, and a vector with a single zero digit.
Digits will be stored in order from least to most significant. All operations will be implemented so that after each of them the result doesn't have any leading zeros, as long as operands didn't have any leading zeros either. All operations which might result in a number with leading zeros should be followed by code which removes them. Note that in this representation there are two valid notations for number zero: an empty vector, and a vector with a single zero digit.

### Output

Expand Down
2 changes: 1 addition & 1 deletion src/algebra/binary-exp.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ a_{31} & a_ {32} & a_ {33} & a_ {34} \\
a_{41} & a_ {42} & a_ {43} & a_ {44}
\end{pmatrix}$$

that, when multiplied by a vector with the old coordinates and an unit gives a new vector with the new coordinates and an unit:
that, when multiplied by a vector with the old coordinates and a unit gives a new vector with the new coordinates and a unit:

$$\begin{pmatrix} x & y & z & 1 \end{pmatrix} \cdot
\begin{pmatrix}
Expand Down
2 changes: 1 addition & 1 deletion src/algebra/chinese-remainder-theorem.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ $$\left\{\begin{align}
a & \equiv 2 \pmod{6}
\end{align}\right.$$

It is pretty simple to determine is a system has a solution.
It is pretty simple to determine if a system has a solution.
And if it has one, we can use the original algorithm to solve a slightly modified system of congruences.

A single congruence $a \equiv a_i \pmod{m_i}$ is equivalent to the system of congruences $a \equiv a_i \pmod{p_j^{n_j}}$ where $p_1^{n_1} p_2^{n_2}\cdots p_k^{n_k}$ is the prime factorization of $m_i$.
Expand Down
2 changes: 1 addition & 1 deletion src/algebra/discrete-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ With this change, the complexity of the algorithm is still the same, but now the
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.

Problems often ask for the minimum $x$ which satisfies the solution.
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.
It is possible to get all answers and take the minimum, or reduce the first found answer using [Euler's theorem](phi-function.md#application), but we can be smart about the order in which we calculate values and ensure the first answer we find is the minimum.

```{.cpp file=discrete_log}
// Returns minimum x for which a ^ x % m = b % m, a and m are coprime.
Expand Down
17 changes: 8 additions & 9 deletions src/algebra/factorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ By looking at the squares $a^2$ modulo a fixed small number, it can be observed

## Pollard's $p - 1$ method { data-toc-label="Pollard's <script type='math/tex'>p - 1</script> method" }

It is very likely that at least one factor of a number is $B$**-powersmooth** for small $B$.
$B$-powersmooth means that every prime power $d^k$ that divides $p-1$ is at most $B$.
It is very likely that a number $n$ has at least one prime factor $p$ such that $p - 1$ is $\mathrm{B}$**-powersmooth** for small $\mathrm{B}$. An integer $m$ is said to be $\mathrm{B}$-powersmooth if every prime power dividing $m$ is at most $\mathrm{B}$. Formally, let $\mathrm{B} \geqslant 1$ and let $m$ be any positive integer. Suppose the prime factorization of $m$ is $m = \prod {q_i}^{e_i}$, where each $q_i$ is a prime and $e_i \geqslant 1$. Then $m$ is $\mathrm{B}$-powersmooth if, for all $i$, ${q_i}^{e_i} \leqslant \mathrm{B}$.
E.g. the prime factorization of $4817191$ is $1303 \cdot 3697$.
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$.
In 1974 John Pollard invented a method to extracts $B$-powersmooth factors from a composite number.
And the values, $1303 - 1$ and $3697 - 1$, are $31$-powersmooth and $16$-powersmooth respectively, because $1303 - 1 = 2 \cdot 3 \cdot 7 \cdot 31$ and $3697 - 1 = 2^4 \cdot 3 \cdot 7 \cdot 11$.
In 1974 John Pollard invented a method to extract factors $p$, s.t. $p-1$ is $\mathrm{B}$-powersmooth, from a composite number.

The idea comes from [Fermat's little theorem](phi-function.md#application).
Let a factorization of $n$ be $n = p \cdot q$.
Expand All @@ -180,7 +179,7 @@ This means that $a^M - 1 = p \cdot r$, and because of that also $p ~|~ \gcd(a^M

Therefore, if $p - 1$ for a factor $p$ of $n$ divides $M$, we can extract a factor using [Euclid's algorithm](euclid-algorithm.md).

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)$.
It is clear, that the smallest $M$ that is a multiple of every $\mathrm{B}$-powersmooth number is $\text{lcm}(1,~2~,3~,4~,~\dots,~B)$.
Or alternatively:

$$M = \prod_{\text{prime } q \le B} q^{\lfloor \log_q B \rfloor}$$
Expand All @@ -189,11 +188,11 @@ Notice, if $p-1$ divides $M$ for all prime factors $p$ of $n$, then $\gcd(a^M -
In this case we don't receive a factor.
Therefore, we will try to perform the $\gcd$ multiple times, while we compute $M$.

Some composite numbers don't have $B$-powersmooth factors for small $B$.
For example, the factors of the composite number $100~000~000~000~000~493 = 763~013 \cdot 131~059~365~961$ are $190~753$-powersmooth and $1~092~161~383$-powersmooth.
We will have to choose $B >= 190~753$ to factorize the number.
Some composite numbers don't have factors $p$ s.t. $p-1$ is $\mathrm{B}$-powersmooth for small $\mathrm{B}$.
For example, for the composite number $100~000~000~000~000~493 = 763~013 \cdot 131~059~365~961$, values $p-1$ are $190~753$-powersmooth and $1~092~161~383$-powersmooth correspondingly.
We will have to choose $B \geq 190~753$ to factorize the number.

In the following implementation we start with $B = 10$ and increase $B$ after each each iteration.
In the following implementation we start with $\mathrm{B} = 10$ and increase $\mathrm{B}$ after each each iteration.

```{.cpp file=factorization_p_minus_1}
long long pollards_p_minus_1(long long n) {
Expand Down
60 changes: 57 additions & 3 deletions src/algebra/fibonacci-numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Fibonacci numbers possess a lot of interesting properties. Here are a few of the

$$F_{n-1} F_{n+1} - F_n^2 = (-1)^n$$

>This can be proved by induction. A one-line proof by Knuth comes from taking the determinant of the 2x2 matrix form below.

* The "addition" rule:

$$F_{n+k} = F_k F_{n+1} + F_{k-1} F_n$$
Expand Down Expand Up @@ -116,11 +118,63 @@ In this way, we obtain a linear solution, $O(n)$ time, saving all the values pri

### Matrix form

It is easy to prove the following relation:
To go from $(F_n, F_{n-1})$ to $(F_{n+1}, F_n)$, we can express the linear recurrence as a 2x2 matrix multiplication:

$$\begin{pmatrix} 1 & 1 \cr 1 & 0 \cr\end{pmatrix} ^ n = \begin{pmatrix} F_{n+1} & F_{n} \cr F_{n} & F_{n-1} \cr\end{pmatrix}$$
$$
\begin{pmatrix}
1 & 1 \\
1 & 0
\end{pmatrix}
\begin{pmatrix}
F_n \\
F_{n-1}
\end{pmatrix}
=
\begin{pmatrix}
F_n + F_{n-1} \\
F_{n}
\end{pmatrix}
=
\begin{pmatrix}
F_{n+1} \\
F_{n}
\end{pmatrix}
$$

This lets us treat iterating the recurrence as repeated matrix multiplication, which has nice properties. In particular,

$$
\begin{pmatrix}
1 & 1 \\
1 & 0
\end{pmatrix}^n
\begin{pmatrix}
F_1 \\
F_0
\end{pmatrix}
=
\begin{pmatrix}
F_{n+1} \\
F_{n}
\end{pmatrix}
$$

where $F_1 = 1, F_0 = 0$.
In fact, since

$$
\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}
= \begin{pmatrix} F_2 & F_1 \\ F_1 & F_0 \end{pmatrix}
$$

we can use the matrix directly:

$$
\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}^n
= \begin{pmatrix} F_{n+1} & F_n \\ F_n & F_{n-1} \end{pmatrix}
$$

Thus, in order to find $F_n$ in $O(log n)$ time, we must raise the matrix to n. (See [Binary exponentiation](binary-exp.md))
Thus, in order to find $F_n$ in $O(\log n)$ time, we must raise the matrix to n. (See [Binary exponentiation](binary-exp.md))

```{.cpp file=fibonacci_matrix}
struct matrix {
Expand Down
2 changes: 1 addition & 1 deletion src/algebra/linear-diophantine-equation.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $$a x_g + b y_g = g$$

If $c$ is divisible by $g = \gcd(a, b)$, then the given Diophantine equation has a solution, otherwise it does not have any solution. The proof is straight-forward: a linear combination of two numbers is divisible by their common divisor.

Now supposed that $c$ is divisible by $g$, then we have:
Now suppose that $c$ is divisible by $g$, then we have:

$$a \cdot x_g \cdot \frac{c}{g} + b \cdot y_g \cdot \frac{c}{g} = c$$

Expand Down
2 changes: 1 addition & 1 deletion src/algebra/polynomial.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ This algorithm was mentioned in [Schönhage's article](http://algo.inria.fr/semi

$$A^{-1}(x) \equiv \frac{1}{A(x)} \equiv \frac{A(-x)}{A(x)A(-x)} \equiv \frac{A(-x)}{T(x^2)} \pmod{x^k}$$

Note that $T(x)$ can be computed with a single multiplication, after which we're only interested in the first half of coefficients of its inverse series. This effectively reduces the initial problem of computing $A^{-1} \pmod{x^k}$ to computing $T^{-1} \pmod{x^{\lfloor k / 2 \rfloor}}$.
Note that $T(x)$ can be computed with a single multiplication, after which we're only interested in the first half of coefficients of its inverse series. This effectively reduces the initial problem of computing $A^{-1} \pmod{x^k}$ to computing $T^{-1} \pmod{x^{\lceil k / 2 \rceil}}$.

The complexity of this method can be estimated as

Expand Down
9 changes: 9 additions & 0 deletions src/combinatorics/burnside.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,12 @@ int solve(int n, int m) {
* [CSES - Counting Grids](https://cses.fi/problemset/task/2210)
* [Codeforces - Buildings](https://codeforces.com/gym/101873/problem/B)
* [CS Academy - Cube Coloring](https://csacademy.com/contest/beta-round-8/task/cube-coloring/)
* [Codeforces - Side Transmutations](https://codeforces.com/contest/1065/problem/E)
* [LightOJ - Necklace](https://vjudge.net/problem/LightOJ-1419)
* [POJ - Necklace of Beads](http://poj.org/problem?id=1286)
* [CodeChef - Lucy and Flowers](https://www.codechef.com/problems/DECORATE)
* [HackerRank - Count the Necklaces](https://www.hackerrank.com/contests/infinitum12/challenges/count-the-necklaces)
* [POJ - Magic Bracelet](http://poj.org/problem?id=2888)
* [SPOJ - Sorting Machine](https://www.spoj.com/problems/SRTMACH/)
* [Project Euler - Pizza Toppings](https://projecteuler.net/problem=281)
* [ICPC 2011 SERCP - Alphabet Soup](https://basecamp.eolymp.com/tr/problems/3064)
3 changes: 2 additions & 1 deletion src/data_structures/stack_queue_modification.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ first we will modify a stack in a way that allows us to find the smallest elemen

## Stack modification

We want to modify the stack data structure in such a way, that it possible to find the smallest element in the stack in $O(1)$ time, while maintaining the same asymptotic behavior for adding and removing elements from the stack.
We want to modify the stack data structure in such a way, that it is possible to find the smallest element in the stack in $O(1)$ time, while maintaining the same asymptotic behavior for adding and removing elements from the stack.
Quick reminder, on a stack we only add and remove elements on one end.

To do this, we will not only store the elements in the stack, but we will store them in pairs: the element itself and the minimum in the stack starting from this element and below.
Expand Down Expand Up @@ -187,5 +187,6 @@ Since all operations with the queue are performed in constant time on average, t

## Practice Problems
* [Queries with Fixed Length](https://www.hackerrank.com/challenges/queries-with-fixed-length/problem)
* [Sliding Window Minimum](https://cses.fi/problemset/task/3221)
* [Binary Land](https://www.codechef.com/MAY20A/problems/BINLAND)

2 changes: 1 addition & 1 deletion src/data_structures/treap.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Alternatively, insert can be done by splitting the initial treap on $X$ and doin
<img src="https://upload.wikimedia.org/wikipedia/commons/6/62/Treap_erase.svg" width="500px"/>
</center>

Implementation of **Erase ($X$)** is also clear. First we descend in the tree (as in a regular binary search tree by $X$), looking for the element we want to delete. Once the node is found, we call **Merge** on it children and put the return value of the operation in the place of the element we're deleting.
Implementation of **Erase ($X$)** is also clear. First we descend in the tree (as in a regular binary search tree by $X$), looking for the element we want to delete. Once the node is found, we call **Merge** on its children and put the return value of the operation in the place of the element we're deleting.

Alternatively, we can factor out the subtree holding $X$ with $2$ split operations and merge the remaining treaps (see the picture).

Expand Down
2 changes: 1 addition & 1 deletion src/geometry/basic-geometry.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ double angle(point2d a, point2d b) {
```

To see the next important property we should take a look at the set of points $\mathbf r$ for which $\mathbf r\cdot \mathbf a = C$ for some fixed constant $C$.
You can see that this set of points is exactly the set of points for which the projection onto $\mathbf a$ is the point $C \cdot \dfrac{\mathbf a}{|\mathbf a|}$ and they form a hyperplane orthogonal to $\mathbf a$.
You can see that this set of points is exactly the set of points for which the projection onto $\mathbf a$ is the point $C \cdot \dfrac{\mathbf a}{|\mathbf a| ^ 2}$ and they form a hyperplane orthogonal to $\mathbf a$.
You can see the vector $\mathbf a$ alongside with several such vectors having same dot product with it in 2D on the picture below:

<div style="text-align: center;">
Expand Down
Loading
Loading