Skip to content

Commit 9d95f0a

Browse files
committed
추가 작업 진행
1 parent 2497cd1 commit 9d95f0a

File tree

23 files changed

+852
-1
lines changed

23 files changed

+852
-1
lines changed

README.ko-KR.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ _다른 언어로 보실 수 있습니다:_
5050
* `B` [Fibonacci Number](src/algorithms/math/fibonacci)
5151
* `B` [Primality Test](src/algorithms/math/primality-test) (시험 분할 방법)
5252
* `B` [Euclidean Algorithm](src/algorithms/math/euclidean-algorithm) - 최대 공약수(GCD) 계산
53-
* `B` [Least Common Multiple](src/algorithms/math/least-common-multiple) (LCM)
53+
* `B` [Least Common Multiple](src/algorithms/math/least-common-multiple) - 최소 공배수(LCM) 계산
5454
* `A` [Integer Partition](src/algorithms/math/integer-partition)
5555
* `B` [Sieve of Eratosthenes](src/algorithms/math/sieve-of-eratosthenes) - 주어진 한도까지 모든 소수를 찾는 것
5656
* `B` [Is Power of Two](src/algorithms/math/is-power-of-two) - 수치가 2의 거듭 제곱인지 (순진 및 비트 알고리즘)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Bit Manipulation
2+
3+
#### 비트 가져 오기
4+
5+
이 메서드는 해당 비트를 0 번째 위치로 이동합니다. 그런 다음 '0001`과 같은 비트 패턴을 가진 AND 연산을 수행합니다. 해당 번호를 제외한 원래 번호의 모든 비트가 지워집니다. 관련 비트가 1이면 결과는 '1'이고, 그렇지 않으면 결과는 '0'입니다.
6+
7+
> 자세한 것은`getBit` 함수를 참고하십시오.
8+
9+
#### 비트 설정
10+
11+
이 방법은`bitPosition` 비트에 의해`1`을 시프트하여`00100`과 같은 값을 생성합니다. 그런 다음 특정 비트를 '1'로 설정하는 'OR'연산을 수행하지만 숫자의 다른 비트에는 영향을 미치지 않습니다.
12+
13+
> 자세한 것은`setBit` 함수를 참고하십시오.
14+
15+
#### 비트 지우기
16+
17+
이 방법은`bitPosition` 비트에 의해`1`을 시프트하여`00100`과 같은 값을 생성합니다. 그런 다음 이 마스크를 반전하여 '11011'과 같은 숫자를 얻습니다. 그런 다음 AND와 연산이 숫자와 마스크에 모두 적용됩니다. 이 작업은 비트를 설정 해제합니다.
18+
19+
> 자세한 것은`clearBit` 함수를 참고하십시오.
20+
21+
#### 비트 갱신
22+
23+
이 방법은 "비트 지우기"및 "비트 설정"방법의 조합입니다.
24+
25+
> 자세한 것은`updateBit` 함수를 참고하십시오.
26+
27+
#### 2로 곱하기
28+
29+
이 방법은 원래 숫자를 1 비트 왼쪽으로 이동합니다. 따라서 모든 이진수 구성 요소 (2의 제곱)에 2가 곱해 지므로 숫자 자체에 2가 곱 해집니다.
30+
31+
```
32+
Before the shift
33+
Number: 0b0101 = 5
34+
Powers of two: 0 + 2^2 + 0 + 2^0
35+
36+
After the shift
37+
Number: 0b1010 = 10
38+
Powers of two: 2^3 + 0 + 2^1 + 0
39+
```
40+
41+
> 자세한 것은`multiplyByTwo` 함수를 참고하십시오.
42+
43+
#### 2로 나누기
44+
45+
이 방법은 원래 숫자를 오른쪽으로 1 비트 씩 이동합니다. 따라서 모든 2 진수 구성 요소 (2의 제곱)는 2로 나누어지고 따라서 숫자 자체는 나머지없이 2로 나눕니다.
46+
47+
```
48+
Before the shift
49+
Number: 0b0101 = 5
50+
Powers of two: 0 + 2^2 + 0 + 2^0
51+
52+
After the shift
53+
Number: 0b0010 = 2
54+
Powers of two: 0 + 0 + 2^1 + 0
55+
```
56+
57+
> 자세한 내용은`divideByTwo` 함수를 참고하십시오.
58+
59+
#### 부호 변경
60+
61+
이 메서드는 양수가 음수가 되도록합니다. 이렇게 하려면 "Two's Complement" 접근법을 사용합니다. 이 방법은 숫자의 모든 비트를 반전시키고 1을 더하는 방식으로 수행합니다.
62+
63+
```
64+
1101 -3
65+
1110 -2
66+
1111 -1
67+
0000 0
68+
0001 1
69+
0010 2
70+
0011 3
71+
```
72+
73+
> 자세한 내용은`switchSign` 함수를 참고하십시오.
74+
75+
## 레퍼런스
76+
77+
- [Bit Manipulation on YouTube](https://www.youtube.com/watch?v=NLKQEOgBAnw&t=0s&index=28&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
78+
- [Negative Numbers in binary on YouTube](https://www.youtube.com/watch?v=4qH4unVtJkE&t=0s&index=30&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
79+
- [Bit Hacks on stanford.edu](https://graphics.stanford.edu/~seander/bithacks.html)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 유클리드 알고리즘
2+
3+
수학에서 유클리드 알고리즘은 최대 공약수(GCD)를 계산하는 데 효율적인 방법입니다. 최대공약수는 두 숫자의 나머지를 남기지 않고 두 숫자를 나누는 가장 큰 숫자입니다.
4+
5+
유클리드 알고리즘은 더 큰 숫자가 더 작은 숫자와의 차이로 대체되면 두 숫자의 최대 공약수가 변하지 않는다는 원칙에 기반합니다. 예를 들어 `252``105`의 최대공약수는 `21`(`252 = 21 × 12``105 = 21 × 5`) 이고, `105``252 - 105 = 147`의 최대공약수 역시 `21`입니다. 이 대체가 두 숫자 중 큰 숫자를 줄이기 때문에이 과정을 반복하면 두 숫자가 동일해질 때까지 작은 숫자 쌍이 연속적으로 제공됩니다. 그 때, 그들은 원래의 두 숫자의 GCD입니다.
6+
7+
단계들을 반대로함으로써, 최대공약수는 양수 또는 음의 정수, 예를 들어, `21 = 5 × 105 + (-2) × 252`을 곱한 2 개의 원래 수의 합으로 표현 될 수 있습니다. 이러한 방식으로 최대공약수를 항상 표현할 수 있다는 사실을 Bézout의 정체성이라고합니다.
8+
9+
![GCD](https://upload.wikimedia.org/wikipedia/commons/3/37/Euclid%27s_algorithm_Book_VII_Proposition_2_3.png)
10+
11+
유클리드는 두 개의 시작 길이 인 `BA``DC`의 최대 공약수 (GCD)를 찾는 방법으로 둘 다 공통 "단위"길이의 배수로 정의됩니다. `DC`는 길이가 더 짧고 `BA`를 채우는 데 사용되지만, 남은 `EA``DC`미만이므로 한 번만 사용됩니다. 이제 EA는 더 짧은 길이의 `DC`를 (두 번) 채우고, 남은 `FC``EA`보다 짧습니다. 그러면 `FC``EA`를 (3 번) 채웁니다. 나머지가 없으므로 프로세스는 `FC``GCD`인 것으로 끝납니다. 오른쪽에 Nicomachus의 '49'와 '21'의 예제는 최대공약수는 7이 나온다. (히스 1908 : 300에서 파생 됨)
12+
13+
![GCD](https://upload.wikimedia.org/wikipedia/commons/7/74/24x60.svg)
14+
15+
`24 x 60`사각형은 10개의 `12 x 12`정사각형 타일로 덮여 있으며, `12``24``60`의 GCD입니다. 보다 일반적으로, `a-by-b`사각형은 `c``a``b`의 공통 제수 일 경우에만 길이가 `c`인 정사각형 타일로 덮을 수 있습니다.
16+
17+
![GCD](https://upload.wikimedia.org/wikipedia/commons/1/1c/Euclidean_algorithm_1071_462.gif)
18+
19+
유클리드 알고리즘의 뺄셈 기반 애니메이션.
20+
초기 직사각형의 크기는 `a = 1071``b = 462`입니다. `462 × 462` 크기의 사각형이 그 안에 배치되어 `462 × 147` 사각형이 남습니다. 이 직사각형은 `21 × 147`사각형이 남을 때까지 `147 × 147`정사각형으로 바둑판 식으로 배열되며, `21 × 21`정사각형으로 바둑판 식으로 배열되며 덮여지지 않는 영역은 남지 않습니다.
21+
가장 작은 정사각형 크기 인 `21``1071``462`의 GCD입니다.
22+
23+
## 레퍼런스
24+
25+
[Wikipedia](https://en.wikipedia.org/wiki/Euclidean_algorithm)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Factorial
2+
3+
수학에서 'n!'으로 표시된 음수가 아닌 정수 'n'의 계승 값은 'n'보다 작거나 같은 모든 양의 정수의 곱입니다. 예를 들면:
4+
5+
```
6+
5! = 5 * 4 * 3 * 2 * 1 = 120
7+
```
8+
9+
| n | n! |
10+
| ----- | --------------------------: |
11+
| 0 | 1 |
12+
| 1 | 1 |
13+
| 2 | 2 |
14+
| 3 | 6 |
15+
| 4 | 24 |
16+
| 5 | 120 |
17+
| 6 | 720 |
18+
| 7 | 5 040 |
19+
| 8 | 40 320 |
20+
| 9 | 362 880 |
21+
| 10 | 3 628 800 |
22+
| 11 | 39 916 800 |
23+
| 12 | 479 001 600 |
24+
| 13 | 6 227 020 800 |
25+
| 14 | 87 178 291 200 |
26+
| 15 | 1 307 674 368 000 |
27+
28+
## 레퍼런스
29+
30+
[Wikipedia](https://en.wikipedia.org/wiki/Factorial)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Fibonacci Number
2+
3+
수학에서 피보나치 수는 피보나치 수열이라 불리는 다음 정수 계열의 수이고 처음 두 개 이후의 모든 수는 앞의 두 수의 합계입니다:
4+
5+
`0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...`
6+
7+
한 변의 길이가 연속되는 사각형을 가진 기와 피보나치 수
8+
9+
![피보나치](https://upload.wikimedia.org/wikipedia/commons/d/db/34%2A21-FibonacciBlocks.png)
10+
11+
피보나치 나선형 (Fibonacci spiral) : 피보나치 타일링에서 정사각형의 대각선을 연결하는 원형 호를 그리면서 생성 된 황금 나선의 근사값;[4] 이 크기는 1, 1, 2, 3, 5, 8, 13 및 21 크기의 사각형을 사용합니다.
12+
13+
![피보나치 나선형](https://upload.wikimedia.org/wikipedia/commons/2/2e/FibonacciSpiral.svg)
14+
15+
## 레퍼런스
16+
17+
[Wikipedia](https://en.wikipedia.org/wiki/Fibonacci_number)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# 정수 파티션
2+
3+
수론과 결합론에서 양의 정수 `n` (**정수 파티션**이라고도 함)의 파티션은 양의 정수의 합으로 `n`을 쓰는 방법입니다.
4+
5+
그들의 summand의 순서에서만 다른 2 개의 합계는 동일한 파티션으로 간주됩니다.
6+
예를 들어, `4`는 다섯 가지 방식으로 분할 될 수 있습니다:
7+
8+
```
9+
4
10+
3 + 1
11+
2 + 2
12+
2 + 1 + 1
13+
1 + 1 + 1 + 1
14+
```
15+
16+
순서에 의존하는 합 `1 + 3``3 + 1`과 같은 파티션이고, `1 + 2 + 1``1 + 1 + 2`는 동일한 파티션 `2 + 1 + 1`으로 표현됩니다.
17+
18+
Young diagrams associated to the partitions of the positive
19+
integers `1` through `8`. They are arranged so that images
20+
under the reflection about the main diagonal of the square
21+
are conjugate partitions.
22+
23+
![Integer Partition](https://upload.wikimedia.org/wikipedia/commons/d/d8/Ferrer_partitioning_diagrams.svg)
24+
25+
## References
26+
27+
- [Wikipedia](https://en.wikipedia.org/wiki/Partition_(number_theory))
28+
- [YouTube](https://www.youtube.com/watch?v=ZaVM057DuzE&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# 2의 거듭 제곱 판별
2+
3+
주어진 양의 정수가 2의 거듭 제곱인지 알아내는 함수를 작성하십시오.
4+
5+
**순수 해법**
6+
7+
순수 해법에서는 숫자가 `1`이되지 않는 한 `2`로 나누고, 그 때마다 나머지가 항상 `0`인 것을 확인합니다. 그렇지 않으면 숫자는 `2`의 거듭 제곱이 될 수 없습니다.
8+
9+
**비트단위 해법**
10+
11+
이진 형식의 2의 제곱은 항상 단 하나의 비트를가집니다. 유일한 예외는 부호있는 정수 (예 : `-128`의 값을 갖는 `8`비트 부호있는 정수는 `10000000`과 같습니다.)입니다.
12+
13+
```
14+
1: 0001
15+
2: 0010
16+
4: 0100
17+
8: 1000
18+
```
19+
20+
따라서 숫자가 `0`보다 큰지 확인한 후 비트 해킹을 사용하여 하나의 비트 만 설정되어 있는지 테스트 할 수 있습니다.
21+
22+
```
23+
number & (number - 1)
24+
```
25+
26+
예를 들어 번호가 `8`이면 다음과 같이 보입니다.:
27+
28+
```
29+
1000
30+
- 0001
31+
----
32+
0111
33+
34+
1000
35+
& 0111
36+
----
37+
0000
38+
```
39+
40+
## 예제
41+
42+
- [GeeksForGeeks](https://www.geeksforgeeks.org/program-to-find-whether-a-no-is-power-of-two/)
43+
- [Bitwise Solution on Stanford](http://www.graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2)
44+
- [Binary number subtraction on YouTube](https://www.youtube.com/watch?v=S9LJknZTyos&t=0s&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8&index=66)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# 최소 공배수
2+
3+
산술과 수론에서, 일반적으로 `LCM (a, b)`로 표시되는 두 정수 `a``b`의 최소 공배수는 `a``b` 둘 다 나눌 수 있는 가장 작은 양의 정수입니다. 0으로 나누어지는 정수가 정의되지 않기 때문에, 이 정의는 `a``b`가 모두 0과 다른 경우에만 의미가 있습니다. 그러나 일부 저작자는`lcm (a, 0)`을 모든`a`에 대해`0`으로 정의합니다. 이는`lcm`을 나눗셈의 격자에서 가장 작은 상한으로 가져간 결과입니다.
4+
5+
## 예제
6+
7+
`4``6`의 최소공배수(LCM)은 무엇인가?
8+
9+
`4`의 배수는 다음과 같다:
10+
11+
```
12+
4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, ...
13+
```
14+
15+
그리고 `6`의 배수는 다음과 같다.
16+
17+
```
18+
6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, ...
19+
```
20+
21+
'4'와 '6'의 공통 배수는 단순히 두 목록에있는 숫자입니다:
22+
23+
```
24+
12, 24, 36, 48, 60, 72, ....
25+
```
26+
27+
그래서, `4``6`의 처음 몇 개의 공통 배수 목록에서, 최소 공배수는 `12`입니다.
28+
29+
## 최소 공배수 계산
30+
31+
The following formula reduces the problem of computing the least common multiple to the problem of computing the greatest common divisor (GCD), also known as the greatest common factor:
32+
33+
```
34+
lcm(a, b) = |a * b| / gcd(a, b)
35+
```
36+
37+
![LCM](https://upload.wikimedia.org/wikipedia/commons/c/c9/Symmetrical_5-set_Venn_diagram_LCM_2_3_4_5_7.svg)
38+
39+
A Venn diagram showing the least common multiples of combinations of `2`, `3`, `4`, `5` and `7` (`6` is skipped as it is `2 × 3`, both of which are already represented).
40+
41+
For example, a card game which requires its cards to be
42+
divided equally among up to `5` players requires at least `60`
43+
cards, the number at the intersection of the `2`, `3`, `4`
44+
and `5` sets, but not the `7` set.
45+
46+
## References
47+
48+
[Wikipedia](https://en.wikipedia.org/wiki/Least_common_multiple)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# 루후이 π 알고리즘
2+
3+
Liu Hui remarked in his commentary to The Nine Chapters on the Mathematical Art, that the ratio of the circumference of an inscribed hexagon to the diameter of the circle was `three`, hence `π` must be greater than three. He went on to provide a detailed step-by-step description of an iterative algorithm to calculate `π` to any required accuracy based on bisecting polygons; he calculated `π` to between `3.141024` and `3.142708` with a 96-gon; he suggested that `3.14` was a good enough approximation, and expressed `π` as `157/50`; he admitted that this number was a bit small. Later he invented an ingenious quick method to improve on it, and obtained `π ≈ 3.1416` with only a 96-gon, with an accuracy comparable to that from a 1536-gon. His most important contribution in this area was his simple iterative `π` algorithm.
4+
5+
## Area of a circle
6+
7+
Liu Hui argued:
8+
9+
> Multiply one side of a hexagon by the radius (of its
10+
circumcircle), then multiply this by three, to yield the
11+
area of a dodecagon; if we cut a hexagon into a
12+
dodecagon, multiply its side by its radius, then again
13+
multiply by six, we get the area of a 24-gon; the finer
14+
we cut, the smaller the loss with respect to the area
15+
of circle, thus with further cut after cut, the area of
16+
the resulting polygon will coincide and become one with
17+
the circle; there will be no loss
18+
19+
![Liu Hui](https://upload.wikimedia.org/wikipedia/commons/6/69/Cutcircle2.svg)
20+
21+
Liu Hui's method of calculating the area of a circle.
22+
23+
Further, Liu Hui proved that the area of a circle is half of its circumference
24+
multiplied by its radius. He said:
25+
26+
> Between a polygon and a circle, there is excess radius. Multiply the excess
27+
radius by a side of the polygon. The resulting area exceeds the boundary of
28+
the circle
29+
30+
In the diagram `d = excess radius`. Multiplying `d` by one side results in
31+
oblong `ABCD` which exceeds the boundary of the circle. If a side of the polygon
32+
is small (i.e. there is a very large number of sides), then the excess radius
33+
will be small, hence excess area will be small.
34+
35+
> Multiply the side of a polygon by its radius, and the area doubles;
36+
hence multiply half the circumference by the radius to yield the area of circle.
37+
38+
![Liu Hui](https://upload.wikimedia.org/wikipedia/commons/9/95/Cutcircle.svg)
39+
40+
The area within a circle is equal to the radius multiplied by half the
41+
circumference, or `A = r x C/2 = r x r x π`.
42+
43+
## Iterative algorithm
44+
45+
Liu Hui began with an inscribed hexagon. Let `M` be the length of one side `AB` of
46+
hexagon, `r` is the radius of circle.
47+
48+
![Liu Hui](https://upload.wikimedia.org/wikipedia/commons/4/46/Liuhui_geyuanshu.svg)
49+
50+
Bisect `AB` with line `OPC`, `AC` becomes one side of dodecagon (12-gon), let
51+
its length be `m`. Let the length of `PC` be `j` and the length of `OP` be `G`.
52+
53+
`AOP`, `APC` are two right angle triangles. Liu Hui used
54+
the [Gou Gu](https://en.wikipedia.org/wiki/Pythagorean_theorem) (Pythagorean theorem)
55+
theorem repetitively:
56+
57+
![](https://wikimedia.org/api/rest_v1/media/math/render/svg/dbfc192c78539c3901c7bad470302ededb76f813)
58+
59+
![](https://wikimedia.org/api/rest_v1/media/math/render/svg/ccd12a402367c2d6614c88e75006d50bfc3a9929)
60+
61+
![](https://wikimedia.org/api/rest_v1/media/math/render/svg/65d77869fc02c302d2d46d45f75ad7e79ae524fb)
62+
63+
![](https://wikimedia.org/api/rest_v1/media/math/render/svg/a7a0d0d7f505a0f434e5dd80c2fef6d2b30d6100)
64+
65+
![](https://wikimedia.org/api/rest_v1/media/math/render/svg/c31b9acf38f9d1a248d4023c3bf286bd03007f37)
66+
67+
![](https://wikimedia.org/api/rest_v1/media/math/render/svg/0dee798efb0b1e3e64d6b3542106cb3ecaa4a383)
68+
69+
![](https://wikimedia.org/api/rest_v1/media/math/render/svg/3ffeafe88d2983b364ad3442746063e3207fe842)
70+
71+
72+
From here, there is now a technique to determine `m` from `M`, which gives the
73+
side length for a polygon with twice the number of edges. Starting with a
74+
hexagon, Liu Hui could determine the side length of a dodecagon using this
75+
formula. Then continue repetitively to determine the side length of a
76+
24-gon given the side length of a dodecagon. He could do this recursively as
77+
many times as necessary. Knowing how to determine the area of these polygons,
78+
Liu Hui could then approximate `π`.
79+
80+
## References
81+
82+
- [Wikipedia](https://en.wikipedia.org/wiki/Liu_Hui%27s_%CF%80_algorithm)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 소수 테스트
2+
3+
** 소수 ** (또는 ** 소수 **)는 두 개의 더 작은 자연수를 곱하여 형성 할 수없는 '1'보다 큰 자연수입니다. '소수'가 아닌 자연수를 합성수라고합니다. 예를 들어 '5'는 소수로, '1 × 5'또는 '5 × 1'이라는 제품으로 쓰는 유일한 방법은 '5'자체를 포함하기 때문입니다. 그러나 '6'은 둘 다 '6'보다 작은 두 개의 숫자 (2 × 3)의 곱이므로 합성수입니다.
4+
5+
![Prime Numbers](https://upload.wikimedia.org/wikipedia/commons/f/f0/Primes-vs-composites.svg)
6+
7+
** 소수 테스트 **는 입력 숫자가 소수인지 여부를 결정하는 알고리즘입니다. 다른 수학 분야 중에서도 암호학에 사용됩니다. 인수분해와 달리 소수 테스트는 일반적으로 입력 요소가 소수인지 아닌지만을 나타내는 소수 요소를 제공하지 않습니다. 인수분해는 계산적으로 어려운 문제로 생각되지만 소수 테스트는 비교적 쉽습니다 (실행 시간은 입력 크기에서 다항식입니다).
8+
9+
## 레퍼런스
10+
11+
- [Prime Numbers on Wikipedia](https://en.wikipedia.org/wiki/Prime_number)
12+
- [Primality Test on Wikipedia](https://en.wikipedia.org/wiki/Primality_test)

0 commit comments

Comments
 (0)