Opening#13087

Opening (Editorial)

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 :

a_n-a_1 = a_{\lceil \frac{n}{2} \rceil}

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

(n-1)m = a_1+(\lceil \frac{n}{2} \rceil-1)m
(n-1)m = a_1+\boxed{(\lceil \frac{n}{2} \rceil-1)m}

Moving the boxed part to Left Hand Side (LHS)

(n-1-\lceil \frac{n}{2} \rceil+1)m = a_1

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

\boxed{a_1=m \cdot \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()