文章目录
数学是一切理科学习的基石
− {\large\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad-} −鲁迅
0 x 00 0x00 0x00.引入
在 C + + C++ C++的学习中, 除了基础算法, 还包括一定的基础数论知识 似乎是高中的知识呢. 之后, 我们就可以快乐地迎接毒瘤出题人的考验毒打了
0 x 01 0x01 0x01.整除
一.定义
设 a , b ∈ Z ( a ≠ 0 ) a,b \in \mathbb{Z}\ (a \not= 0) a,b∈Z (a=0) 如果 ∃ \exists ∃ 一个 Z q \mathbb{Z}\ q Z q, 使得 a q = b a \, q = b aq=b, 则 b b b 能被 a a a 整除, 记作 a ∣ b a\mid b a∣b, 否则记作 a ∤ b a\nmid b \quad a∤b
(看起来人畜无害的样子)
二.性质
(1) 如果 a ∣ b a \mid b a∣b 且 b ∣ c b \mid c b∣c, 则 a ∣ c a \mid c a∣c
Q Q Q:就不能写易证吗?
A A A:你在数学题里写易证试试,看老师不给你扣完 !
− {\large\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad-} − c q b z g m cqbzgm cqbzgm
证:
令 a x = b ( x ∈ Z a \, x = b (x \in \mathbb{Z} ax=b(x∈Z 且 x ≠ 0 ) x \not= 0) x=0)
b y = c ( y ∈ Z \;\;\;\;b \, y = c (y \in \mathbb{Z} by=c(y∈Z 且 y ≠ 0 ) y \not= 0) y=0)
∴ a x y = c \therefore \ a \, x \, y = c ∴ axy=c
∴ a ∣ c \therefore \ a \mid c ∴ a∣c
(2) 如果 a ∣ b a \mid b a∣b 且 a ∣ c ⟺ a \mid c \iff \! a∣c⟺ ∀ x , y ∈ Z \! \forall x,y \in \mathbb{Z} ∀x,y∈Z 有 a ∣ b x + c y a \mid b \, x + c\, y a∣bx+cy
证:
令 a p = b ( p ∈ Z a \, p = b (p \in \mathbb{Z} ap=b(p∈Z 且 p ≠ 0 ) p \not= 0) p=0)
a q = c ( q ∈ Z \;\;\;\;a \, q = c (q \in \mathbb{Z} aq=c(q∈Z 且 q ≠ 0 ) q \not= 0) q=0)
∵ b x + c y = a p x + a q y \because b \, x + c \, y = a \, p \, x + a \, q \,y ∵bx+cy=apx+aqy
= a ( p x + q y ) \qquad \qquad \quad \;\;\; = a \, (p \, x + q \, y) =a(px+qy)
∴ a ∣ b x + c y \therefore a \mid b \, x + c \, y ∴a∣bx+cy
(3) 设 m ∈ Z m \in \mathbb{Z} m∈Z 且 m ≠ 0 m \not= 0 m=0 则 a ∣ b ⟺ m a ∣ m b a \mid b \iff m \, a \mid m \, b a∣b⟺ma∣mb
证:
令 a x = b ( x ∈ Z a \, x = b (x \in \mathbb{Z} ax=b(x∈Z 且 x ≠ 0 ) x \not= 0) x=0)
∴ a x m = b m ⟺ x a m = b m \therefore a \, x \, m = b \, m \iff x \, a \, m = b \, m ∴axm=bm⟺xam=bm
∴ a m ∣ b m \therefore a \, m \mid b \, m ∴am∣bm
(4) 设 x , y ∈ Z x, y \in \mathbb{Z} x,y∈Z 满足下式: a x + b y = 1 a \, x + b \, y = 1 ax+by=1 且 a ∣ n , b ∣ n a \mid n , b \mid n a∣n,b∣n 那么 a b ∣ n a \, b \mid n ab∣n
证:
令 n = a p = b q ( p , q ∈ Z ) n = a \, p = b \, q \ (p, q \in \mathbb{Z}) n=ap=bq (p,q∈Z)
∴ a , b ≠ 0 \therefore a, b \not= 0 ∴a,b=0
∴ a x + b y = 1 ⇒ x b + y a = 1 a b \therefore a \, x + b \, y = 1 \Rightarrow \frac{x}{b} + \frac{y}{a} = \frac{1}{a \, b} ∴ax+by=1⇒bx+ay=ab1
∴ n a b = n ( x b + y a ) \therefore \frac{n}{a \, b} = n \, (\frac{x}{b} + \frac{y}{a}) ∴abn=n(bx+ay)
= n x b + n y a \quad \; \, \; \; \; =\frac{n \, x}{b} + \frac{n \, y}{a} =bnx+any
= p x + q y \quad \; \; \; \; \, = p \,x + q \, y =px+qy
∴ n a b ∈ Z \therefore \frac{n}{a \, b} \in \mathbb{Z} ∴abn∈Z
∴ a b ∣ n \therefore a \, b \mid n ∴ab∣n
(5) 若 b = q d + c ( q ∈ Z ) b = q \, d + c \ (q \in \mathbb{Z}) b=qd+c (q∈Z)那么 d ∣ b ⟺ d ∣ c d \mid b \iff d \mid c d∣b⟺d∣c [ ^[ [1 ] ^] ]
即证:
1. { d ∣ c b = q a + c ⇒ d ∣ b 1.\begin{cases} d \mid c\\ b = q \, a + c&\end{cases} \Rightarrow d \mid b 1.{ d∣cb=qa+c⇒d∣b
2. { d ∣ b b = q a + c ⇒ d ∣ c 2.\begin{cases} d \mid b\\ b = q \, a + c&\end{cases} \Rightarrow d \mid c 2.{ d∣bb=qa+c⇒d∣c
证:
令 d x = c ( x ∈ Z ) d \, x = c \ (x \in \mathbb{Z}) dx=c (x∈Z) ( 1 ) (1) (1)
∴ b = q + x d \therefore b = q \, + x \, d ∴b=q+xd
= d ( q + x ) \quad \; \, \,= d \, ( q + x) =d(q+x)
∴ d ∣ b \therefore d \mid b ∴d∣b
令 d y = c ( y ∈ Z ) d \, y = c \ (y \in \mathbb{Z}) dy=c (y∈Z) ( 2 ) (2) (2)
∴ d y = q d + c \therefore d \, y = q \, d+ c ∴dy=qd+c
∴ c = d ( y − q ) \therefore c = d \, (y - q) ∴c=d(y−q)
∴ d ∣ c \therefore d \mid c ∴d∣c
∴ d ∣ b ⇔ d ∣ c \therefore d \mid b \Leftrightarrow d \mid c ∴d∣b⇔d∣c
三.推论
请先阅读 0 x 02 0x02 0x02模运算.
(1)设 a ∈ Z a \in \mathbb{Z} a∈Z 若 2 ∣ ( a % 10 ) 2 \mid (a \% 10) 2∣(a%10), 则 2 ∣ a 2 \mid a 2∣a
证:
设 x = ( a % 10 ) x = (a\%10) x=(a%10);
记 A A A 为除末位外的部分, 则 a = 10 × A + x a = 10 \! \times \! A + x a=10×A+x
∴ a % 2 = ( ( 10 × A ) % 2 + x % 2 ) % 2 \therefore a \% 2 = ((10\!\times\!A) \% 2 + x \% 2) \% 2 ∴a%2=((10×A)%2+x%2)%2
∵ 2 ∣ x \because 2 \mid x ∵2∣x
∴ 2 ∣ a \therefore 2 \mid a ∴2∣a
(2)设 a ∈ Z a \in \mathbb{Z} a∈Z 若 4 ∣ ( a % 100 ) 4 \mid (a \% 100) 4∣(a%100), 则 4 ∣ a 4 \mid a 4∣a
证:
设 x = ( a % 100 ) x = (a\%100) x=(a%100);
记 A A A 为除后两位外的部分, 则 a = 100 × A + x a = 100 \! \times \! A + x a=100×A+x
∴ a % 4 = ( ( 100 × A ) % 4 + x % 4 ) % 4 \therefore a \% 4 = ((100\!\times\!A) \% 4 + x \% 4) \% 4 ∴a%4=((100×A)%4+x%4)%4
∵ 4 ∣ x \because 4 \mid x ∵4∣x
∴ 4 ∣ a \therefore 4 \mid a ∴4∣a
(3)设 a ∈ Z a \in \mathbb{Z} a∈Z 若 8 ∣ ( a % 1000 ) 8 \mid (a \% 1000) 8∣(a%1000), 则 8 ∣ a 8 \mid a 8∣a
证:
设 x = ( a % 1000 ) x = (a\%1000) x=(a%1000);
记 A A A 为除后三位外的部分, 则 a = 1000 × A + x a = 1000 \! \times \! A + x a=1000×A+x
∴ a % 8 = ( ( 1000 × A ) % 8 + x % 8 ) % 8 \therefore a \% 8 = ((1000\!\times\!A) \% 8 + x \% 8) \% 8 ∴a%8=((1000×A)%8+x%8)%8
∵ 8 ∣ x \because 8 \mid x ∵8∣x
∴ 8 ∣ a \therefore 8 \mid a ∴8∣a
(4)设 a = a n a n − 1 … a 2 a 1 ‾ a = \overline{a_{n}a_{n - 1}\dots a_{2}a_{1}} a=a