CHOCCUT - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: raysh07
Tester: iceknight1093
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

You’re given an N\times M chocolate bar, made of NM squares.
You want to cut it into two equal pieces with a single horizontal/vertical cut.
Is this possible?

EXPLANATION:

If N is even, making a horizontal cut along the middle will give us two pieces of size \frac{N}{2} \times M each, so the answer is Yes.

Similarly, if M is even, making a vertical cut along the middle will give us two N\times \frac{M}{2} pieces, and again the answer is Yes.

That leaves the case where both N and M are odd.
In this case, the answer is No, since no matter how we cut the chocolate into two parts, one will have an odd number of pieces and one will have an even number so they cannot be equal.

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (PyPy3)
for _ in range(int(input())):
    n, m = map(int, input().split())
    print('Yes' if n%2 == 0 or m%2 == 0 else 'No')