problem 120 square remainders https projecteuler netproblem120 description let r be the remainder when a1n a1n is divided by a2 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 on expanding the terms we get 2 if n is even and 2an if n is odd for maximizing the value 2an aa n a 12 integer division returns rmax for 3 a n as explained above solution10 300 solution100 330750 solution1000 333082500 returns r_max for 3 a n as explained above solution 10 300 solution 100 330750 solution 1000 333082500
def solution(n: int = 1000) -> int:
    
    return sum(2 * a * ((a - 1) // 2) for a in range(3, n + 1))


if __name__ == "__main__":
    print(solution())