性质
对于任意的正整数 a a a、 b b b、 c c c,都必然有 ⌊ ⌊ a b ⌋ c ⌋ = ⌊ a b c ⌋ \lfloor \frac{\lfloor \frac{a}{b} \rfloor}{c} \rfloor=\lfloor \frac{a}{bc} \rfloor ⌊c⌊ba⌋⌋=⌊bca⌋。
证明
设 ⌊ a b ⌋ = x \lfloor \frac{a}{b} \rfloor=x ⌊ba⌋=x,设 a = x ⋅ b + y a=x\cdot b + y a=x⋅b+y,于是就有 0 ≤ y < b 0\le y < b 0≤y<b。
同理,设 ⌊ ⌊ a b ⌋ c ⌋ = z \lfloor \frac{\lfloor \frac{a}{b} \rfloor}{c} \rfloor=z ⌊c⌊ba⌋⌋=z,设 ⌊ a b ⌋ = z ⋅ c + r \lfloor \frac{a}{b} \rfloor=z\cdot c + r ⌊ba⌋=z⋅c+r,于是就有 0 ≤ r < c 0\le r < c 0≤r<c。
于是就有 x = z ⋅ c + r x=z\cdot c + r x=z⋅c+r,所以 a = ( z ⋅ c + r ) ⋅ b + y = z ⋅ b c + ( r ⋅ b + y ) a=(z\cdot c+r)\cdot b +y=z\cdot bc+(r\cdot b + y) a=(z⋅c+r)⋅b+y=z⋅bc+(r⋅b+y)。
可以假设 y = b − b 0 ( 1 ≤ b 0 ≤ b ) y=b-b_0(1\leq b_0 \leq b) y=b−b0(1≤b0≤b),以及 r = c − c 0 ( 1 ≤ c 0 ≤ c ) r=c-c_0(1\leq c_0 \leq c) r=c−c0(1≤c0≤c)。
所以 a = z ⋅ b c + [ ( c − c 0 ) ⋅ b + ( b − b 0 ) ] = z ⋅ b c + ( b c − c 0 b + b − b 0 ) = z ⋅ b c + [ b c − ( c 0 − 1 ) ⋅ b − b 0 ] a=z\cdot bc+[(c-c_0)\cdot b+(b-b_0)]=z\cdot bc+(bc-c_0b+b-b_0)=z\cdot bc+[bc-(c_0-1)\cdot b-b_0] a=z⋅bc+[(c−c0)⋅b+(b−b0)]=z⋅bc+(bc−c0b+b−b0)=z⋅bc+[bc−(c0−1)⋅b−b0]。因为 c 0 ≥ 1 c_0\ge 1 c0≥1,所以 b c − ( c 0 − 1 ) ⋅ b − b 0 < b c bc-(c_0-1)\cdot b -b_0 < bc bc−(c0−1)⋅b−b0<bc,所以代入得到 ⌊ a b c ⌋ = ⌊ z ⋅ b c + [ b c − ( c 0 − 1 ) ⋅ b − b 0 ] b c ⌋ = ⌊ z ⋅ b c b c + b c − ( c 0 − 1 ) ⋅ b − b 0 b c ⌋ = z \lfloor \frac{a}{bc} \rfloor=\lfloor \frac{z\cdot bc+[bc-(c_0-1)\cdot b-b_0]}{bc}\rfloor=\lfloor\frac{z\cdot bc}{bc}+\frac{bc-(c_0-1)\cdot b-b_0}{bc}\rfloor=z ⌊bca⌋=⌊bcz⋅bc+[bc−(c0−1)⋅b−b0]⌋=⌊bcz⋅bc+bcbc−(c0−1)⋅b−b0⌋=z。于是得证。
应用
商式取模开括号:
⌊ ( a m o d b c ) b ⌋ = ⌊ a − ⌊ a b c ⌋ ⋅ b c b ⌋ = ⌊ a b ⌋ − ⌊ a b c ⌋ ⋅ c = ⌊ a b ⌋ − ⌊ ⌊ a b ⌋ c ⌋ ⋅ c = ⌊ a b ⌋ m o d c \lfloor\frac{(a\mod bc)}{b}\rfloor=\lfloor\frac{a-{\lfloor\frac{a}{bc}\rfloor}\cdot bc}{b}\rfloor=\lfloor\frac{a}{b}\rfloor-{\lfloor\frac{a}{bc}\rfloor}\cdot c=\lfloor\frac{a}{b}\rfloor-{\lfloor\frac{\lfloor\frac{a}{b}\rfloor}{c}\rfloor}\cdot c=\lfloor\frac{a}{b}\rfloor \mod c ⌊b(amodbc)⌋=⌊ba−⌊bca⌋⋅bc⌋=⌊ba⌋−⌊bca⌋⋅c=⌊ba⌋−⌊c⌊ba⌋⌋⋅c=⌊ba⌋modc