Skip to content

Latest commit

 

History

History
23 lines (15 loc) · 1.06 KB

120. Square remainders.md

File metadata and controls

23 lines (15 loc) · 1.06 KB

Question

Let r be the remainder when eq is divided by eq. For example, if a = 7 and n = 3, then r = 42: 63 + 83 = 728 ≡ 42 mod 49. And as n varies, so too will r, but for a = 7 it turns out that rmax = 42. For 3 ≤ a ≤ 1000, find ∑ rmax.

Solution

eq

eq

If n is even, then r = 2; if n is odd, we have

eq

To maximise r, we need to have 2n < a which gives n <= (a - 1) // 2

def p120():
    return sum(2 * ((a - 1) // 2) * a  for a in range(3, 1001))