Problem:


Problem H: Squid Multiplication

Squid Eiko loves mathematics.
Especially she loves to think about integer.
One day, Eiko found a math problem from a website.

"A sequence b ={ai + aj | i &lt j }  is generated from a sequence a ={a0 , ... , an | ai is even if i is 0, otherwise ai is odd}. Given the sequence b , find the sequence a ."

This problem is easy for Eiko and she feels boring. So, she made a new problem by modifying this problem .

"A sequence b ={ai *aj | i < j }  is generated from a sequence a ={ a0, ... , an | ai is even if  i  is 0, otherwise ai is odd}. Given the sequence b , find the sequence a ."

Your task is to solve the problem made by Eiko.

Input

Input consists of multiple datasets.

Each dataset is given by following formats.

n
b0 b1 ... bn*(n+1)/2-1

n is the number of odd integers in the sequence a. The range of n is 2 ≤ n ≤ 250.
bi is separated by a space.
Each bi is 1 ≤ bi ≤ 263-1.
The end of the input consists of a single 0.

Output

For each dataset, you should output two lines.
First line contains a0, an even number in the sequence a.
The second line contains n odd elements separated by a space. The odd elements are sorted by increasing order.
You can assume that the result is greater than or equal to 1 and less than or equal to 231-1.

Sample input

3
6 10 14 15 21 35
2
30 42 35
0

Sample output

2
3 5 7
6
5 7



Sample input:
3
6 10 14 15 21 35
2
30 42 35
0


Sample output:
2
3 5 7
6
5 7

Submission status: Wrong Answer

Solution code:
import math

while(1):
    n=int(raw_input())
    if n==0:    break
    A=map(int,raw_input().split())
    E=[]
    D=[]
    for a in A:
        if a%2==0:
            E.append(a)
        else:
            D.append(a)
    E.sort()
    D.sort()
    
    g=2
    el=E[0]
    for i in range(32):
        if el>>i%2:
            g**=i
    E=[e/g for e in E]
    
    k1=math.sqrt(D[0]*E[0]/E[1])
    ga =E[0]/k1
    E=[e/ga for e in E]
    
    print int(g*ga)
    print ' '.join(map(str,map(int,E)))

Submission status: Accepted

Solution code:
# AOJ 1069: Squid Multiplication
# Python3 2018.7.10 bal4u

def gcd(a, b):
	while b != 0:
		r = a % b
		a, b = b, r
	return a

while True:
	n = int(input())
	if n == 0: break
	even, odd = [], []
	b = list(map(int, input().split()))
	for i in b:
		if i & 1: odd.append(i)
		else: even.append(i)
	even.sort()
	odd.sort()
	e1, e2, o1 = even[0], even[1], odd[0];
	g = gcd(e1, o1)
	e1, o1 = e1//g, o1//g
	g = gcd(e2, o1)
	e2, o1 = e2//g, o1//g
	g = int((e1 * e2)**0.5)
	print(g)
	print(*[i//g for i in even])

Submission status: Accepted

Solution code:
import math

while(1):
    n=int(raw_input())
    if n==0:    break
    A=map(int,raw_input().split())
    E=[]
    D=[]
    for a in A:
        if a%2==0:
            E.append(a)
        else:
            D.append(a)
    E.sort()
    D.sort()
    
    g=2
    el=E[0]
    for i in range(100):
        if el>>i%2:
            g**=i
            break
    E=[e/g for e in E]
    
    k1=int(math.sqrt(D[0]*E[0]/E[1]))
    ga =E[0]/k1
    E=[e/ga for e in E]
    
    print int(g*ga)
    print ' '.join(map(str,map(int,E)))

Submission status: Accepted

Solution code:
while 1:
	n=input()
	if n==0:break
	b=map(int,raw_input().split())
	i=2
	c=int((b[n-2]*b[n-1]/b[-1])**0.5)
	print c
	print " ".join(map(str,sorted([b[i]/c for i in range(n)])))

Submission status: Accepted

Solution code:
while 1:
	n=input()
	if n==0:break
	b=map(int,raw_input().split())
	c=int((b[n-2]*b[n-1]/b[-1])**0.5)
	print c
	print " ".join(map(str,sorted([b[i]/c for i in range(n)])))

Submission status: Accepted

Solution code:
while(True):
    n = int(input())
    if n == 0 : exit()
    b = list(map(int, input().split()))
    even, odd = b[:n], b[n:]
    sq = even[0]*even[1]//odd[0]
    l, r = 1, 2**32
    while r-l > 1:
        mid = (l+r)//2
        if mid*mid <= sq : l = mid
        else             : r = mid
    print(l)
    print(" ".join(map(str, sorted([x//l for x in even]))))