The chef has a recipe he wishes to use for his guests,
but the recipe will make far more food than he can serve to the guests.
The chef therefore would like to make a reduced version of the recipe which has the same ratios of ingredients, but makes less food.
The chef, however, does not like fractions.
The original recipe contains only whole numbers of ingredients,
and the chef wants the reduced recipe to only contain whole numbers of ingredients as well.
Help the chef determine how much of each ingredient to use in order to make as little food as possible.

------ Input ------ 

Input will begin with an integer T, the number of test cases.
Each test case consists of a single line.
The line begins with a positive integer N, the number of ingredients.
N integers follow, each indicating the quantity of a particular ingredient that is used.

------ Output ------ 

For each test case, output exactly N space-separated integers on a line,
giving the quantity of each ingredient that the chef should use in order to make as little food as possible.

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

T ≤ 100 

2 ≤ N ≤ 50

All ingredient quantities are between 1 and 1000, inclusive.

----- Sample Input 1 ------ 
3
2 4 4
3 2 3 4
4 3 15 9 6
----- Sample Output 1 ------ 
1 1
2 3 4
1 5 3 2

Difficulty: EASY
Tags: Number theory

Mathematics

Starter code:

Solutions:
t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	r = a[1:]
	hcf = 1
	for i in range(2, min(r) + 1):
		for j in r:
			if j % i != 0:
				break
		else:
			hcf = i
	new = []
	for i in r:
		new.append(i // hcf)
	for i in new:
		print(i, end=' ')
	print()


T = int(input())
for i in range(T):
	l = list(map(int, input().split()[1:]))
	n = min(l)
	while n:
		if all([i % n == 0 for i in l]):
			print(*[i // n for i in l])
			break
		n = n - 1


for i in range(int(input())):
	a = list(map(int, input().split()))
	b = a[1:]
	n = min(b)
	while n:
		if all((i % n == 0 for i in b)):
			print(*[i // n for i in b])
			break
		n -= 1


n = int(input())

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
for i in range(n):
	lis = list(map(int, input().split()))[1:]
	result = lis[0]
	for i in lis[1:]:
		result = gcd(result, i)
	flag = True
	l2 = []
	for i in range(len(lis)):
		if lis[i] % result != 0:
			flag = False
			break
		else:
			l2.append(lis[i] // result)
	if flag:
		print(*l2, sep=' ')
	else:
		print(*lis, sep=' ')


def gcd(lst):
	cd_lst = []
	x = max(lst)
	for i in range(2, x + 1):
		count = 0
		for j in lst:
			if j % i == 0:
				count = count + 1
		if count == len(lst):
			cd_lst.append(i)
	if len(cd_lst) == 0:
		return 0
	else:
		return max(cd_lst)
test = int(input())
for I in range(test):
	lst = list(map(int, input().split()))
	del lst[0]
	x = len(lst)
	ans = gcd(lst)
	if ans == 0:
		for i in range(len(lst)):
			if i != x - 1:
				print(lst[i], end=' ')
			else:
				print(lst[x - 1])
	else:
		for i in range(len(lst)):
			if i != x - 1:
				y = lst[i] // ans
				print(y, end=' ')
			else:
				y = lst[i] // ans
				print(y)


import math
for _ in range(int(input())):
	l = list(map(int, input().split()))
	num1 = l[1]
	num2 = l[2]
	g = math.gcd(num1, num2)
	for i in range(3, l[0]):
		g = math.gcd(g, l[i])
	li = l[1:]
	for j in range(len(li)):
		li[j] = li[j] // g
	print(*li)


t = int(input())
for i in range(t):
	n = list(map(int, input().split()))
	n.remove(n[0])
	q = min(n)
	while q >= 0:
		r = []
		for i in n:
			if i % q == 0:
				r.append(i)
		if len(r) == len(n):
			for i in range(0, len(n)):
				n[i] = n[i] // q
				print(n[i], end=' ')
			break
		q -= 1
	print()


import math
t = int(input())
for _ in range(t):
	(n, *ingredients) = map(int, input().split())
	gcd = ingredients[0]
	for i in range(1, n):
		gcd = math.gcd(gcd, ingredients[i])
	for i in range(n):
		print(ingredients[i] // gcd, end=' ')
	print()


import math
for i in range(int(input())):
	p = list(map(int, input().split()))
	q = p[1]
	for i in range(2, p[0] + 1):
		q = math.gcd(q, p[i])
	for j in range(1, p[0] + 1):
		print(p[j] // q, end=' ')
	print()


import math
t = int(input())
for i in range(t):
	list1 = list(map(int, input().split()))
	list2 = list1[1:]
	n = list1[0]
	min1 = min(list2)
	count = 0
	div = math.gcd(list2[0], list2[1])
	for j in range(2, n):
		div = math.gcd(div, list2[j])
	for j in range(0, n):
		print(list2[j] // div, end=' ')
	print()


import math as math
for i in range(int(input())):
	l = list(map(int, input().split()))
	z = []
	p = 0
	for j in range(1, len(l)):
		p = math.gcd(p, l[j])
	for j in range(1, len(l)):
		print(l[j] // p, end=' ')
	print()


import math
for i in range(int(input())):
	a = list(map(int, input().split()))
	b = a[1]
	for i in range(2, a[0] + 1):
		b = math.gcd(b, a[i])
	for j in range(1, a[0] + 1):
		print(a[j] // b, end=' ')
	print()


import math
for i in range(int(input())):
	lst = list(map(int, input().split()))
	n = lst[0]
	lst = lst[1:]
	gcd = math.gcd(lst[0], lst[1])
	for i in range(2, n):
		gcd = math.gcd(gcd, lst[i])
	lst2 = list(map(lambda x: x // gcd, lst))
	print(*lst2)


import math
for i in range(0, int(input())):
	ans = 1
	list1 = list(map(int, input().split()))
	a = math.gcd(list1[1], list1[2])
	for j in range(3, list1[0] + 1):
		a = math.gcd(a, list1[j])
	for k in range(1, len(list1)):
		list1[k] = list1[k] // a
	for k in range(1, len(list1)):
		print(list1[k], end=' ')
	print()


t = int(input())
for j in range(t):
	lst = list(map(int, input().split()))
	l = lst[1:]
	n = min(l)
	while n:
		if all([i % n == 0 for i in l]):
			print(*[i // n for i in l])
			break
		n = n - 1


def gcd(n1, n2):
	while n2:
		(n1, n2) = (n2, n1 % n2)
	return n1
for _ in range(int(input())):
	s = list(map(int, input().split()))
	n = s[0]
	l = s[1:len(s)]
	n1 = l[0]
	n2 = l[1]
	temp = gcd(n1, n2)
	for i in range(2, len(l)):
		temp = gcd(temp, l[i])
	for i in range(n):
		print(l[i] // temp, end=' ')
	print()


from math import gcd
from functools import reduce
t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	a = len(l)
	l1 = l[1:a]
	x = reduce(gcd, l1)
	for i in l1:
		print(i // x, end=' ')
	print('')


import math
for __ in range(int(input())):
	l = list(map(int, input().split()))
	x = math.gcd(l[1], l[2])
	for i in range(3, l[0] + 1):
		x = math.gcd(x, l[i])
	for i in range(1, l[0] + 1):
		l[i] //= x
	for i in range(1, l[0] + 1):
		print(l[i], end=' ')
	print()


EP = int(input())
for i in range(EP):
	ep = list(map(int, input().split()[1:]))
	pc = min(ep)
	while pc:
		if all([i % pc == 0 for i in ep]):
			print(*[i // pc for i in ep])
			break
		pc = pc - 1


import math
T = int(input())
for t in range(T):
	a = list(map(int, input().split()))
	list1 = list(a[1:])
	arr = []
	l = list1[0]
	for i in range(1, len(list1)):
		l = math.gcd(l, list1[i])
	for i in list1:
		if i % l == 0:
			arr.append(i // l)
	if len(list1) == len(arr):
		print(*arr)
	else:
		print(*list1)


import math
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	m1 = math.gcd(l[1], l[2])
	for i in range(3, len(l)):
		m1 = math.gcd(m1, l[i])
		if m1 == 1:
			break
	for i in range(1, len(l)):
		print(l[i] // m1, end=' ')
	print()


tesva = int(input())
for c in range(tesva):
	z = list(map(int, input().split()[1:]))
	q = min(z)
	while q:
		if all([c % q == 0 for c in z]):
			print(*[c // q for c in z])
			break
		q -= 1


import math
T = int(input())
for i in range(T):
	list1 = list(map(int, input().split()))
	N = list1[0]
	list1.remove(list1[0])
	gcf = 0
	for i in list1:
		gcf = math.gcd(gcf, i)
	for i in list1:
		print(i // gcf, end=' ')
	print()


import math
from functools import reduce
for i in range(int(input())):
	ing = [int(num) for num in input().split()]
	ing.pop(0)
	x = reduce(math.gcd, ing)
	for i in range(len(ing)):
		print(ing[i] // x, end=' ')
	print()


import math
for i in range(int(input())):
	n = list(map(int, input().split()))
	n1 = n[1:]
	l = []
	g = math.gcd(n1[0], n1[1])
	for i in n1:
		g = math.gcd(g, i)
	for i in n1:
		l.append(i // g)
	print(*l)


def getGCD(a, b):
	while a > 0 and b > 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	if a == 0:
		return b
	return a
for _ in range(int(input())):
	l = list(map(int, input().split()))
	n = l.remove(l[0])
	gcd = 0
	for i in range(len(l)):
		gcd = getGCD(gcd, l[i])
	l[:] = [x // gcd for x in l]
	for i in range(len(l)):
		print(l[i], end=' ')
	print()


t = int(input())
for i in range(t):
	List = list(map(int, input().split()))
	List1 = list(List[1:])
	l = min(List1)
	while l:
		if all((i % l == 0 for i in List1)):
			print(*[i // l for i in List1])
			break
		l -= 1


def fac(n):
	l = []
	for i in range(2, n // 2 + 1):
		if n % i == 0:
			l.append(i)
	l.append(n)
	l.reverse()
	return l
for i in range(int(input())):
	l = list(map(int, input().split()))
	n = l[0]
	l.remove(l[0])
	l1 = fac(min(l))
	l2 = []
	c1 = 0
	for i in l1:
		c = 0
		for j in l:
			if j % i == 0:
				c = c + 1
				l2.append(j // i)
		if c == n:
			print(*l2)
			c1 = c1 + 1
			break
		else:
			l2 = []
	if c1 == 0:
		print(*l)


from math import gcd
for _ in range(int(input())):
	arr = list(map(int, input().split()))
	n = arr[0]
	a = arr[1]
	for i in range(1, n):
		a = gcd(a, arr[i + 1])
	if gcd == 1:
		for i in range(1, n + 1):
			print(arr[i], end=' ')
	else:
		for i in range(1, n + 1):
			print(arr[i] // a, end=' ')
	print()


for i in range(int(input())):
	L = input().split()
	l = [eval(i) for i in L]
	l.remove(l[0])
	for i in range(min(l), 0, -1):
		count = 0
		for j in l:
			if j % i == 0:
				count += 1
		if count == len(l):
			break
	for j in l:
		print(j // i, end=' ')
	print()


import math
T = int(input())
for i in range(T):
	li = list(map(int, input().split()))
	n = li[0]
	li.remove(li[0])
	gcd = math.gcd(li[0], li[1])
	for j in range(2, n):
		gcd = math.gcd(gcd, li[j])
	for k in range(n):
		li[k] = int(li[k] / gcd)
	print(*li, sep=' ')


for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.remove(l[0])
	n = min(l)
	while n >= 0:
		c = 0
		for i in range(len(l)):
			if l[i] % n == 0:
				c += 1
		if c == len(l):
			for i in range(0, len(l)):
				l[i] = l[i] // n
				print(l[i], end=' ')
			break
		n -= 1
	print()