PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: S. Manuj Nanthan
Tester: Harris Leung
Editorialist: Nishank Suresh
DIFFICULTY:
668
PREREQUISITES:
None
PROBLEM:
Chef has N candies and M friends. Can all the candies be distributed equally among the friends so that everyone receives an equal number of candies?
EXPLANATION:
There are two conditions to check here, let us look at both of them.
- First, every candy should be distributed and everyone needs to receive an equal number of candies. This is only possible when M divides N, and so each person will receive \frac{N}{M} candies.
- Next, everyone needs to receive an even number of candies. From the first condition, we know that each person receives exactly \frac{N}{M} candies. So, check if this number is even or not.
Check both conditions above. The answer is “Yes” if both are true and “No” otherwise.
TIME COMPLEXITY
\mathcal{O}(1) per test case.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
n, m = map(int, input().split())
print('yes' if n%m == 0 and (n//m)%2 == 0 else 'no')