Math Atlas

소수와 소인수분해Primes & Prime Factorization

기초 산술Foundations · 2. 약수와 배수2. Factors & Multiples

연습Practice78
학습 목표
  • 소수와 합성수를 정의하고, 11이 소수도 합성수도 아닌 이유를 설명할 수 있다.
  • 에라토스테네스의 체로 소수를 찾고, 소수 판정 때 "제곱해서 그 수를 넘지 않는 소수까지만" 확인하면 되는 이유를 설명할 수 있다.
  • 수를 소인수분해해 거듭제곱으로 정리하고, 소인수분해로 약수의 개수를 셀 수 있다.
  • 소수가 끝없이 많다는 유클리드의 증명을 따라갈 수 있다.

더 쪼개지지 않는 수

12=3×412 = 3 \times 4처럼 어떤 수는 더 작은 두 수의 곱으로 쪼개진다. 4=2×24 = 2 \times 2로 한 번 더 쪼개면 12=2×2×312 = 2 \times 2 \times 3이고, 여기서 끝이다. 223311과 자기 자신 말고는 약수가 없어서 더 쪼갤 수 없다. 이런 수가 소수다. 곱셈 세계의 원자라고 할 수 있다.

정의소수와 합성수

11보다 큰 자연수 중에서 약수가 11과 자기 자신뿐인 수를 소수, 약수가 그 밖에도 있는 수를 합성수라고 한다. 11은 소수도 합성수도 아니다.

소수: 2,3,5,7,11,13,17,19,23,합성수: 4,6,8,9,10,12,14,15,\text{소수: } 2, 3, 5, 7, 11, 13, 17, 19, 23, \ldots \qquad \text{합성수: } 4, 6, 8, 9, 10, 12, 14, 15, \ldots

11을 따로 빼 두는 데는 이유가 있다. 약수가 11 하나뿐이라 "약수가 두 개"라는 소수의 모양에 맞지 않고, 더 중요하게는 11을 소수로 치면 12=2×2×3=1×2×2×3=1×1×2×2×312 = 2 \times 2 \times 3 = 1 \times 2 \times 2 \times 3 = 1 \times 1 \times 2 \times 2 \times 3처럼 쪼개는 방법이 무한히 많아져 버린다. 잠시 뒤 볼 "쪼개는 방법은 한 가지"라는 사실을 지키기 위해 11은 원자 목록에서 뺀다. 22는 유일한 짝수 소수다. 다른 짝수는 전부 22를 약수로 갖기 때문이다.

에라토스테네스의 체

5050까지의 소수를 한 번에 찾는 방법이 있다. 22부터 5050까지 늘어놓고, 22를 남긴 채 22의 배수를 전부 지운다. 남은 수 중 다음 수 33을 남기고 33의 배수를 지운다. 다음 남은 수 55, 그다음 77에 대해서도 같이 한다. 지워지지 않고 남은 수가 소수다.

1부터 50까지의 체. 2, 3, 5, 7의 배수를 지우고 남은 15개가 소수다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1부터 50까지의 체. 2, 3, 5, 7의 배수를 지우고 남은 15개가 소수다.

77까지만 하고 멈춰도 될까? 5050 이하의 합성수 n=a×bn = a \times b(aa가 작은 쪽)에서 a×an50a \times a \le n \le 50이므로 a7a \le 7이다. aa가 소수가 아니면 aa의 소인수는 더 작다. 그러니 5050 이하의 모든 합성수는 77 이하의 소수 중 하나를 약수로 가지고, 2,3,5,72, 3, 5, 7의 배수를 지우는 것으로 합성수는 전부 걸러진다. 같은 논리가 소수 판정의 지름길이 된다.

정의소수 판정

nn이 소수인지 알아보려면 제곱해서 nn을 넘지 않는 소수들로만 나누어 보면 된다. 어느 것으로도 나누어떨어지지 않으면 소수다.

예제 1 · 소수처럼 보이는 수

97979191은 소수인가?

풀이. 10×10=100>9710 \times 10 = 100 > 97이므로 1010 미만의 소수 2,3,5,72, 3, 5, 7만 확인한다. 9797은 홀수, 자릿수 합 161633의 배수가 아니고, 끝자리가 5500이 아니며, 97=7×13+697 = 7 \times 13 + 6. 넷 다 안 되므로 9797은 소수다.

9191: 2,3,52, 3, 5는 같은 이유로 안 되지만 91=7×1391 = 7 \times 13. 합성수다.

검산: 7×13=917 \times 13 = 91 ✓. 97978,98, 9로도 나누어 볼 필요가 없다. 88이나 99가 약수라면 그 약수 2233이 먼저 걸렸을 것이다 ✓.

소인수분해

합성수를 소수만의 곱으로 쓰는 것을 소인수분해라 하고, 곱에 나오는 소수를 소인수라 한다. 360360을 분해해 보자. 두 수의 곱으로 쪼개고, 쪼개진 수가 합성수면 또 쪼갠다.

360의 인수 나무. 36 × 10으로 쪼개기 시작해 끝에 남는 잎은 2, 2, 2, 3, 3, 5. 360 36 10 4 9 2 5 2 2 3 3 360 = 2 × 2 × 2 × 3 × 3 × 5 = 2³ × 3² × 5
360의 인수 나무. 36 × 10으로 쪼개기 시작해 끝에 남는 잎은 2, 2, 2, 3, 3, 5.

360=36×10=(4×9)×(2×5)=2×2×2×3×3×5.360 = 36 \times 10 = (4 \times 9) \times (2 \times 5) = 2 \times 2 \times 2 \times 3 \times 3 \times 5.

같은 수를 여러 번 곱한 것은 줄여 쓴다. 2×2×22 \times 2 \times 2232^3("22의 세제곱")이라 쓰고, 위에 작게 쓴 33지수라 부른다. 그러면

360=23×32×5.360 = 2^3 \times 3^2 \times 5.

360=12×30360 = 12 \times 30이나 360=8×45360 = 8 \times 45로 시작해도 나무의 모양은 달라지지만 마지막 잎은 똑같이 2,2,2,3,3,52, 2, 2, 3, 3, 5다. 어떤 자연수든 소인수분해의 결과는 순서를 빼면 한 가지뿐이다. 이 사실은 이 단원의 모든 도구가 서 있는 땅인데, 증명은 경시 과정의 정수론에서 한다. 지금은 믿고 쓰자.

나무 대신 나눗셈 사다리로 해도 된다. 가장 작은 소수부터 나누어떨어지는 동안 계속 나누고, 안 되면 다음 소수로 넘어간다.

예제 2 · 나눗셈 사다리

504504를 소인수분해하여라.

풀이. 504÷2=252504 \div 2 = 252, 252÷2=126252 \div 2 = 126, 126÷2=63126 \div 2 = 63. 이제 22로는 안 된다. 63÷3=2163 \div 3 = 21, 21÷3=721 \div 3 = 7. 77은 소수이므로 끝.

504=23×32×7.504 = 2^3 \times 3^2 \times 7.

검산: 23=82^3 = 8, 32=93^2 = 9, 8×9×7=5048 \times 9 \times 7 = 504 ✓.

주의

소인수분해는 소수로만 쓴다. 360=8×45360 = 8 \times 45360=23×45360 = 2^3 \times 45는 곱으로 쪼갠 것이지 소인수분해가 아니다. 4545가 아직 32×53^2 \times 5로 쪼개지기 때문이다. 끝에 남은 수가 전부 소수인지 확인하고 멈춘다.

소인수분해로 약수 세기

약수와 배수 차시에서 7272의 약수를 짝지어 1212개 찾았다. 소인수분해 72=23×3272 = 2^3 \times 3^2로 보면 세지 않고도 개수를 알 수 있다. 7272의 약수는 220,1,2,30, 1, 2, 3개 중 몇 개, 330,1,20, 1, 2개 중 몇 개 골라 곱한 수다. 다른 소수는 들어갈 수 없다. 2233 말고 다른 소인수를 가진 수는 7272를 나누지 못하기 때문이다.

30=13^0 = 1 31=33^1 = 3 32=93^2 = 9
20=12^0 = 1 11 33 99
21=22^1 = 2 22 66 1818
22=42^2 = 4 44 1212 3636
23=82^3 = 8 88 2424 7272

22의 개수 44가지와 33의 개수 33가지가 짝지어 표의 칸 4×3=124 \times 3 = 12개를 만들고, 칸마다 다른 약수 하나씩이 들어간다. 그때의 목록과 정확히 같다.

정의약수의 개수

n=pa×qb×n = p^a \times q^b \times \cdots로 소인수분해되면 약수의 개수는 (a+1)×(b+1)×(a + 1) \times (b + 1) \times \cdots이다. 각 소수를 "00개부터 지수 개까지" 고르는 가짓수를 곱한 것이다.

예제 3 · 세지 않고 세기

360360의 약수는 몇 개인가?

풀이. 360=23×32×51360 = 2^3 \times 3^2 \times 5^1이므로 (3+1)×(2+1)×(1+1)=4×3×2=24(3 + 1) \times (2 + 1) \times (1 + 1) = 4 \times 3 \times 2 = 24개.

검산: 짝으로 세어도 된다. 18×18=324360<36118 \times 18 = 324 \le 360 < 361이므로 1818까지 확인 — 1,2,3,4,5,6,8,9,10,12,15,181, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 181212개가 작은 쪽이고 각각 짝이 있으니 2424개 ✓.

약수와 배수 차시의 "약수 개수가 홀수 ⟺ 제곱수"도 여기서 다시 보인다. 3,600=24×32×523{,}600 = 2^4 \times 3^2 \times 5^2처럼 지수가 모두 짝수이면 (4+1)(2+1)(2+1)=45(4 + 1)(2 + 1)(2 + 1) = 45로 홀수이고, 실제로 3,600=(22×3×5)2=6023{,}600 = (2^2 \times 3 \times 5)^2 = 60^2이다. 지수가 하나라도 홀수이면 그 (지수+1)(\text{지수} + 1)이 짝수라 전체가 짝수가 된다.

소수는 끝이 없다

소수 목록은 2,3,5,7,11,2, 3, 5, 7, 11, \ldots로 이어진다. 언젠가 끝날까? 이천 년도 더 전에 유클리드가 끝나지 않는다는 것을 증명했고, 그 논증은 지금도 그대로 통한다.

소수가 유한 개뿐이라서 전부 적을 수 있다고 하자. 그 소수를 모두 곱한 뒤 11을 더한NN을 만든다. NN을 목록의 어떤 소수로 나누어도 나머지가 11이다. 곱한 부분은 나누어떨어지고 더한 11이 남기 때문이다. 그런데 NN11보다 큰 자연수이므로 소수이거나, 소수인 약수를 가진다. 그 소수는 목록의 어느 소수로도 나누어떨어지지 않는 NN을 나누므로 목록에 없던 소수다. 목록이 전부였다는 가정에 모순이다. 그러므로 소수는 끝이 없다.

작은 예로 감을 잡자. 2×3×5×7+1=2112 \times 3 \times 5 \times 7 + 1 = 211은 소수다. 2×3×5×7×11×13+1=30,031=59×5092 \times 3 \times 5 \times 7 \times 11 \times 13 + 1 = 30{,}031 = 59 \times 509는 소수가 아니지만, 그 소인수 5959509509는 곱한 목록에 없던 새 소수다. 증명이 약속한 것은 "NN이 소수"가 아니라 "NN의 소인수가 새 소수"라는 점이다.

참고

소수는 무한히 많지만 규칙적으로 나타나지는 않는다. 100100까지 2525개, 1,0001{,}000까지 168168개로 점점 드물어지고, 2233 말고는 이웃한 소수가 없다(하나는 짝수이므로). 11111313, 17171919처럼 22 차이 나는 쌍이 무한히 많은지는 아직 아무도 모른다.

Goals
  • Define prime and composite numbers, and explain why 11 is neither.
  • Find primes with the sieve of Eratosthenes, and explain why testing a number for primality only needs the primes whose square does not exceed it.
  • Factor a number into primes, write the result with exponents, and count factors from the prime factorization.
  • Follow Euclid's proof that the primes never run out.

Numbers that cannot be split

Some numbers split into a product of smaller numbers, like 12=3×412 = 3 \times 4. Split once more, 4=2×24 = 2 \times 2, and 12=2×2×312 = 2 \times 2 \times 3, where it ends: 22 and 33 have no factors besides 11 and themselves, so they cannot be split further. Such numbers are primes, the atoms of multiplication.

DefinitionPrimes and composites

A whole number greater than 11 whose only factors are 11 and itself is prime; one with additional factors is composite. The number 11 is neither prime nor composite.

Primes: 2,3,5,7,11,13,17,19,23,Composites: 4,6,8,9,10,12,14,15,\text{Primes: } 2, 3, 5, 7, 11, 13, 17, 19, 23, \ldots \qquad \text{Composites: } 4, 6, 8, 9, 10, 12, 14, 15, \ldots

There is a reason for setting 11 aside. Its only factor is 11 itself, so it does not fit the "exactly two factors" shape of a prime; more importantly, if 11 counted as a prime, then 12=2×2×3=1×2×2×3=1×1×2×2×312 = 2 \times 2 \times 3 = 1 \times 2 \times 2 \times 3 = 1 \times 1 \times 2 \times 2 \times 3 would have infinitely many splittings. To protect the fact, coming shortly, that "there is only one way to split," 11 is left off the list of atoms. Note that 22 is the only even prime, since every other even number has 22 as a factor.

The sieve of Eratosthenes

There is a way to find all primes up to 5050 in one sweep. List 22 through 5050. Keep 22 and cross out every other multiple of 22. The next survivor is 33: keep it and cross out its multiples. Do the same with the next survivors, 55 and 77. Whatever is never crossed out is prime.

The sieve from 1 to 50. After crossing out the multiples of 2, 3, 5, and 7, the 15 survivors are the primes. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
The sieve from 1 to 50. After crossing out the multiples of 2, 3, 5, and 7, the 15 survivors are the primes.

Is it safe to stop at 77? Take a composite n=a×bn = a \times b with n50n \le 50 and aa the smaller factor. Then a×an50a \times a \le n \le 50, so a7a \le 7; and if aa is not itself prime, it has an even smaller prime factor. So every composite up to 5050 has a prime factor of at most 77, and crossing out the multiples of 2,3,5,72, 3, 5, 7 catches every composite. The same reasoning gives a shortcut for testing a single number.

DefinitionTesting for primality

To decide whether nn is prime, divide only by the primes whose square does not exceed nn. If none divides evenly, nn is prime.

Example 1 · Numbers that look prime

Are 9797 and 9191 prime?

Solution. Since 10×10=100>9710 \times 10 = 100 > 97, only the primes below 1010 need testing: 2,3,5,72, 3, 5, 7. 9797 is odd; its digit sum 1616 is not a multiple of 33; it does not end in 00 or 55; and 97=7×13+697 = 7 \times 13 + 6. All four fail, so 9797 is prime.

9191: 2,3,52, 3, 5 fail for the same reasons, but 91=7×1391 = 7 \times 13. Composite.

Check: 7×13=917 \times 13 = 91 ✓. There was no need to try 88 or 99 on 9797: if either divided it, its factor 22 or 33 would have been caught first ✓.

Prime factorization

Writing a composite number as a product of primes only is called prime factorization, and the primes involved are its prime factors. Let's factor 360360. Split it into two factors; whenever a factor is composite, split it again.

A factor tree for 360. Starting from 36 × 10, the leaves at the bottom are 2, 2, 2, 3, 3, 5. 360 36 10 4 9 2 5 2 2 3 3 360 = 2 × 2 × 2 × 3 × 3 × 5 = 2³ × 3² × 5
A factor tree for 360. Starting from 36 × 10, the leaves at the bottom are 2, 2, 2, 3, 3, 5.

360=36×10=(4×9)×(2×5)=2×2×2×3×3×5.360 = 36 \times 10 = (4 \times 9) \times (2 \times 5) = 2 \times 2 \times 2 \times 3 \times 3 \times 5.

Repeated factors are abbreviated: 2×2×22 \times 2 \times 2 is written 232^3 ("22 cubed," or "22 to the third"), and the small raised 33 is the exponent. So

360=23×32×5.360 = 2^3 \times 3^2 \times 5.

Starting from 360=12×30360 = 12 \times 30 or 360=8×45360 = 8 \times 45 gives a differently shaped tree, but the leaves at the bottom are the same 2,2,2,3,3,52, 2, 2, 3, 3, 5. For every whole number, the prime factorization is unique apart from the order of the factors. This fact is the ground on which every tool in this unit stands; its proof belongs to the number theory of the competition track. For now, use it with confidence.

Instead of a tree, a division ladder works too: divide by the smallest prime as long as it goes in evenly, then move on to the next prime.

Example 2 · The division ladder

Factor 504504 into primes.

Solution. 504÷2=252504 \div 2 = 252, 252÷2=126252 \div 2 = 126, 126÷2=63126 \div 2 = 63. Now 22 no longer goes in. 63÷3=2163 \div 3 = 21, 21÷3=721 \div 3 = 7. Since 77 is prime, stop.

504=23×32×7.504 = 2^3 \times 3^2 \times 7.

Check: 23=82^3 = 8, 32=93^2 = 9, and 8×9×7=5048 \times 9 \times 7 = 504 ✓.

Watch out

A prime factorization uses primes only. 360=8×45360 = 8 \times 45 and 360=23×45360 = 2^3 \times 45 are splittings, not prime factorizations, because 4545 still splits into 32×53^2 \times 5. Stop only when every number left is prime.

Counting factors from the factorization

In the factors-and-multiples lesson we paired up the factors of 7272 and found 1212 of them. From the factorization 72=23×3272 = 2^3 \times 3^2, the count can be known without listing. A factor of 7272 is built by choosing 0,1,20, 1, 2, or 33 copies of 22 and 0,10, 1, or 22 copies of 33, then multiplying. No other prime can appear, since a number with some other prime factor cannot divide 7272.

30=13^0 = 1 31=33^1 = 3 32=93^2 = 9
20=12^0 = 1 11 33 99
21=22^1 = 2 22 66 1818
22=42^2 = 4 44 1212 3636
23=82^3 = 8 88 2424 7272

Four choices for the 22s and three for the 33s combine into 4×3=124 \times 3 = 12 cells, each holding a different factor. It is exactly that list.

DefinitionThe number of factors

If n=pa×qb×n = p^a \times q^b \times \cdots is the prime factorization, the number of factors of nn is (a+1)×(b+1)×(a + 1) \times (b + 1) \times \cdots: the product of the number of ways to choose each prime, from 00 copies up to the exponent.

Example 3 · Counting without listing

How many factors does 360360 have?

Solution. 360=23×32×51360 = 2^3 \times 3^2 \times 5^1, so there are (3+1)×(2+1)×(1+1)=4×3×2=24(3 + 1) \times (2 + 1) \times (1 + 1) = 4 \times 3 \times 2 = 24 factors.

Check by pairing: since 18×18=324360<36118 \times 18 = 324 \le 360 < 361, test up to 1818. The smaller members are 1,2,3,4,5,6,8,9,10,12,15,181, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, twelve of them, each with a partner, so 2424 ✓.

The factors-and-multiples lesson's "odd number of factors exactly for perfect squares" shows up here too. When every exponent is even, as in 3,600=24×32×523{,}600 = 2^4 \times 3^2 \times 5^2, the count (4+1)(2+1)(2+1)=45(4 + 1)(2 + 1)(2 + 1) = 45 is odd, and indeed 3,600=(22×3×5)2=6023{,}600 = (2^2 \times 3 \times 5)^2 = 60^2. If any exponent is odd, that (exponent+1)(\text{exponent} + 1) is even and so is the whole product.

The primes never run out

The list of primes goes 2,3,5,7,11,2, 3, 5, 7, 11, \ldots. Does it ever stop? More than two thousand years ago Euclid proved that it does not, and his argument works today exactly as it did then.

Suppose there were only finitely many primes, so that all of them could be written down. Form the number NN by multiplying all of them together and adding 11. Dividing NN by any prime on the list leaves remainder 11, because the product part divides evenly and the added 11 is left over. But NN is a whole number greater than 11, so it is either prime or has a prime factor. That prime divides NN, which none of the listed primes does, so it is a prime not on the list. This contradicts the assumption that the list was complete. Therefore the primes never run out.

Small cases give a feel for it. 2×3×5×7+1=2112 \times 3 \times 5 \times 7 + 1 = 211 is prime. 2×3×5×7×11×13+1=30,031=59×5092 \times 3 \times 5 \times 7 \times 11 \times 13 + 1 = 30{,}031 = 59 \times 509 is not prime, but its prime factors 5959 and 509509 are new primes missing from the product. What the proof promises is not "NN is prime" but "the prime factors of NN are new."

Note

The primes are infinite but irregular. There are 2525 of them up to 100100 and 168168 up to 1,0001{,}000, so they thin out; and apart from 22 and 33, no two primes are neighbors, since one of any two neighbors is even. Whether there are infinitely many pairs two apart, like 1111 and 1313 or 1717 and 1919, is a question nobody has answered yet.