Skip to content

Commit f9c6ea6

Browse files
algmyrjakobkogler
authored andcommitted
Small fixes because of PDF (#317)
1 parent 538e1d7 commit f9c6ea6

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/algebra/binary-exp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ $$\begin{align}
3333
3^2 &= \left(3^1\right)^2 = 3^2 = 9 \\\\
3434
3^4 &= \left(3^2\right)^2 = 9^2 = 81 \\\\
3535
3^8 &= \left(3^4\right)^2 = 81^2 = 6561
36-
\end{align}
36+
\end{align}$$
3737

3838
So to get the final answer for $3^{13}$, we only need to multiply three of them (skipping $3^2$ because the corresponding bit in $n$ is not set):
3939
$3^{13} = 6561 \cdot 81 \cdot 3 = 1594323$

src/others/josephus_problem.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@ We will try to find a pattern expressing the answer for the problem $J_{n, k}$ t
1818

1919
Using brute force modeling we can construct a table of values, for example, the following:
2020

21-
$$\begin{matrix} n\setminus k & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\cr
22-
1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\cr
23-
2 & 2 & 1 & 2 & 1 & 2 & 1 & 2 & 1 & 2 & 1\cr
24-
3 & 3 & 3 & 2 & 2 & 1 & 1 & 3 & 3 & 2 & 2\cr
25-
4 & 4 & 1 & 1 & 2 & 2 & 3 & 2 & 3 & 3 & 4\cr
26-
5 & 5 & 3 & 4 & 1 & 2 & 4 & 4 & 1 & 2 & 4\cr
27-
6 & 6 & 5 & 1 & 5 & 1 & 4 & 5 & 3 & 5 & 2\cr
28-
7 & 7 & 7 & 4 & 2 & 6 & 3 & 5 & 4 & 7 & 5\cr
29-
8 & 8 & 1 & 7 & 6 & 3 & 1 & 4 & 4 & 8 & 7\cr
30-
9 & 9 & 3 & 1 & 1 & 8 & 7 & 2 & 3 & 8 & 8\cr
31-
10 & 10 & 5 & 4 & 5 & 3 & 3 & 9 & 1 & 7 & 8\cr
32-
\end{matrix}$$
21+
$$\begin{array}{ccccccccccc}
22+
n\setminus k & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\\\
23+
1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\\\
24+
2 & 2 & 1 & 2 & 1 & 2 & 1 & 2 & 1 & 2 & 1 \\\\
25+
3 & 3 & 3 & 2 & 2 & 1 & 1 & 3 & 3 & 2 & 2 \\\\
26+
4 & 4 & 1 & 1 & 2 & 2 & 3 & 2 & 3 & 3 & 4 \\\\
27+
5 & 5 & 3 & 4 & 1 & 2 & 4 & 4 & 1 & 2 & 4 \\\\
28+
6 & 6 & 5 & 1 & 5 & 1 & 4 & 5 & 3 & 5 & 2 \\\\
29+
7 & 7 & 7 & 4 & 2 & 6 & 3 & 5 & 4 & 7 & 5 \\\\
30+
8 & 8 & 1 & 7 & 6 & 3 & 1 & 4 & 4 & 8 & 7 \\\\
31+
9 & 9 & 3 & 1 & 1 & 8 & 7 & 2 & 3 & 8 & 8 \\\\
32+
10 & 10 & 5 & 4 & 5 & 3 & 3 & 9 & 1 & 7 & 8 \\\\
33+
\end{array}$$
3334

3435
And here we can clearly see the following **pattern**:
3536

@@ -44,15 +45,15 @@ So, we found a solution to the problem of Joseph, working in $O(n)$ operations.
4445

4546
Simple **recursive implementation** (in 1-indexing)
4647

47-
```
48+
```cpp
4849
int josephus(int n, int k) {
4950
return n > 1 ? (joseph(n-1, k) + k - 1) % n + 1 : 1;
5051
}
5152
```
5253
5354
**Non-recursive form** :
5455
55-
```
56+
```cpp
5657
int josephus(int n, int k) {
5758
int res = 0;
5859
for (int i = 1; i <= n; ++i)
@@ -81,7 +82,7 @@ Also, we need to handle the case when $n$ becomes less than $k$ - in this case,
8182

8283
**Implementation** (for convenience in 0-indexing):
8384

84-
```
85+
```cpp
8586
int josephus(int n, int k) {
8687
if (n == 1)
8788
return 0;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy