链式模运算的最大值

Maximum value from chained modulo operation

If n = p % q % r where p, q and r are positive integers and p > q > r, what is the maximum possible value that can be assigned to n? (answer in terms of p, q and/or r)

我是不是更正了,因为表达式是从左到右求值的,那么 n 就等同于 (p % q) % r 因此无论 (p % q) 是什么,n最多只能是r-1?

一般来说,n 的最大值为 min(q - 1, r - 1)

因为:

n = (p % q) % r

然后:

如果 (q - 1) < (r - 1),则 (p % q) < (r - 1),因此 (p % q) % r == (p % q),因此 n <= min(q - 1, r - 1)q - 1

If (q - 1) >= (r - 1) then (as described in his question) n < r - 1 在那种情况下是 min(q - 1, r - 1)

所以:

p > q > r时,那么min(q - 1, r - 1)就是r - 1,所以n最多就是r - 1.