Problem Author: | Hasan Saleh (MathModel) |
Prepared by: | Hasan Saleh (MathModel) |
Edited by: | Hasan Saleh (MathModel) |
The problem can shortened to Given two integers and Give a_1 of a_1,a_2,\ldots,a_n for which
a_{i+1}-a_i=m for all (1 \le i <n)
a_n-a_1=\text{median}
Here , Notice that median is \frac{n}{2} when is even and \frac{n+1}{2} when is odd , this is exactly how ceil function would work so the median always lies in index \lceil \frac{n}{2} \rceil.
a_{i+1}-a_i=m for all (1 \le i <n)
a_n-a_1=a_{\lceil \frac{n}{2} \rceil}
We've this fact :
The General form of A.P. (Arithmetic Progression) is a_i=a_1+m(i-1) since each time we move we to add we get
Moving the boxed part to Left Hand Side (LHS)
Recall the fact that \lfloor \frac{n}{2} \rfloor+\lceil \frac{n}{2} \rceil=n for all integer thus n-\lceil \frac{n}{2} \rceil=\lfloor \frac{n}{2} \rfloor
Complexity is .
def solve():
n,m=map(int,input().split())
print(m*(n//2))
for _ in range(int(input())):
solve()