Kheira's Board Game
Written by Iyed Baassou
Problem Statement
Solution
We are asked to compute the total value of all cells in an board starting at coordinates . Each cell contributes .
The simplest approach is to directly iterate over all cells, sum their contributions, and finally take the result modulo .
This is per test case which is enough for the constraint .
Note that we can take the modulo at every iteration, that would be vital for c++ solution in case of long long overflow.
Implementation
py
t = int(input())
for _ in range(t):
i, j, n = map(int, input().split())
res = 0
for x in range(i, i + n):
for y in range(j, j + n):
res += abs(x - y) + 1
res %= 10**9 + 7
print(res)
