A first-year student, came to your college. Being a good senior, you must tell him if it is possible to go from College Main Gate to Hostel for him.

The college can be visualized on a 2D-plane. Suppose the College Main Gate is situated at origin i.e. at the coordinates (0, 0) and the Hostel is situated at the coordinates (x,y).

As the first-year student wants to explore the college campus further, in one move, he will increase or decrease any coordinate (either the x-coordinate or the y-coordinate) by a value of exactly K.

Is it possible for the first-year student to reach the Hostel?

------ Input Format ------ 

- First line of input contains a single integer T, denoting the number of test cases. Then the description of the T test case follows.
- Each test case contains one line of input.
- The first line contains three integers x, y, K.

------ Output Format ------ 

For each test case, output a single line answer containing a "YES" or "NO" (without quotes).

You may print each character of each string in uppercase or lowercase (for example, the strings without quotes "yEs", "yes", "Yes" and "YES" will all be treated as identical).

------ Constraints ------ 

$1 ≤ T ≤ 600$
$-1000 ≤ x, y ≤ 1000$
$1 ≤ K ≤ 1000$

----- Sample Input 1 ------ 
4
1 2 1
3 -5 2
-9 -6 3
-18 12 5

----- Sample Output 1 ------ 
YES
NO
YES
NO
----- explanation 1 ------ 
Test case 1:
Here $K = 1$, One of the paths that the first-year student can follow is described as: $(0, 0)$ to $(1, 0)$ to $(1, 1)$ to $(1, 2)$. Hence, he can reach the hostel coordinate at $(x, y) = (1, 2)$ with the $K = 1$ constraint.

Test case 2:
As here $K = 2$, it can be proved that there is no path to move from $(0, 0)$ to $(3, -5$) by only increasing or decreasing any coordinate by exactly $K = 2$.

Test case 3:
Here $K = 3$, One of the paths that the first-year student can follow is described as: $(0, 0)$ to $(-3, 0)$ to $(-3, -3)$ to $(-3, -6)$ to $(-6, -6)$ to $(-9, -6)$. Hence, he can reach the hostel coordinate at $(x, y) = (-9, -6)$ with the $K = 3$ constraint.

Difficulty: EASY
Tags: Constructive algorithms

Geometry

Number theory

Mathematics

Ad-hoc

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(x, y, k) = map(int, input().split())
	if x % k == 0 and y % k == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(x, y, k) = map(int, input().split())
	print('NO') if abs(x) % k != 0 or abs(y) % k != 0 else print('YES')


t = int(input())
for i in range(t):
	c = input()
	v = c.split(' ')
	x = int(v[0])
	y = int(v[1])
	k = int(v[2])
	if x % k == 0 and y % k == 0:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	l = []
	l = list(map(int, input().split()))
	(x, y, k) = l
	if abs(x) % k == 0 and abs(y) % k == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	if abs(b) % c != 0 or abs(a) % c != 0:
		print('NO')
	else:
		print('YES')


def check(x, y, k):
	if x % k == 0 and y % k == 0:
		return 'YES'
	return 'NO'
for i in range(int(input())):
	(x, y, k) = input().split()
	(x, y, k) = (int(x), int(y), int(k))
	print(check(x, y, k))


T = int(input())
for _ in range(T):
	(x, y, K) = map(int, input().split())
	print('YES') if abs(x) % K == 0 and abs(y) % K == 0 else print('NO')


t = int(input())
for bunnt in range(t):
	(a, b, k) = map(int, input().split())
	if a % k == 0 and b % k == 0:
		print('YES')
	else:
		print('NO')


tc = int(input())
for _ in range(tc):
	(a, b, k) = map(int, input().split())
	if a % k == 0 and b % k == 0:
		print('YES')
	else:
		print('NO')


for cases in range(int(input())):
	(x, y, num) = map(int, input().split())
	if x % num == 0 and y % num == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for z in range(t):
	(a, b, c) = map(int, input().split())
	if abs(a) % c == 0 and abs(b) % c == 0:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	actual = [0, 0]
	destiny = [int(x) for x in input().split(' ')]
	K = destiny[-1]
	destiny = destiny[:-1]
	if destiny[0] % K != 0 or destiny[1] % K != 0:
		print('NO')
	else:
		print('YES')


a = int(input())
for i in range(a):
	(m, n, k) = map(int, input().split())
	if m % k == 0 and n % k == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	(x, y, k) = map(int, input().split())
	if x % k != 0 or y % k != 0:
		print('NO')
	else:
		print('YES')


def can_reach(x, y, k):
	if x % k == 0 and y % k == 0:
		return 'YES'
	else:
		return 'NO'
T = int(input())
for i in range(T):
	(x, y, k) = map(int, input().split())
	print(can_reach(x, y, k))


t = int(input())
while t > 0:
	(x, y, k) = map(int, input().split())
	if abs(x % k) != 0 or abs(y % k) != 0:
		print('NO')
	else:
		print('YES')
	t = t - 1


for test in range(int(input())):
	(x, y, K) = map(int, input().split())
	if x % K == 0 and y % K == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	l = list(map(int, input().split()))
	if l[0] % l[2] == 0 and l[1] % l[2] == 0:
		print('YES')
	else:
		print('NO')