Chef is making polygon cakes in his kitchen today! 
Since the judge panel is very strict, Chef's cakes must be beautiful and have sharp and precise $internal$ angles in arithmetic progression. 
Given the number of sides, $N$, of the cake Chef is baking today and also the measure of its first angle(smallest angle), $A$, find the measure of the $K^{th}$ angle.

-----Input:-----
- The first line contains a single integer $T$, the number of test cases. 
- The next $T$ lines contain three space separated integers $N$, $A$ and $K$, the number of sides of polygon, the first angle and the $K^{th}$ angle respectively. 

-----Output:-----
For each test case, print two space separated integers $X$ and $Y$, such that the $K^{th}$ angle can be written in the form of $X/Y$ and $gcd(X, Y) = 1$

-----Constraints-----
- $1 \leq T \leq 50$
- $3 \leq N \leq 1000$
- $1 \leq A \leq 1000000000$
- $1 \leq K \leq N$
- It is guaranteed the answer is always valid.

-----Sample Input:-----
1
3 30 2

-----Sample Output:-----
60 1

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Geometry

Number theory

Mathematics


Solutions:
def gcd(A, B):
	if B == 0:
		return A
	else:
		return gcd(B, A % B)
t = int(input())
for _ in range(t):
	(n, a, k) = map(int, input().split())
	num = a * (n * (n - 1)) + (k - 1) * (360 * (n - 2) - 2 * a * n)
	den = n * (n - 1)
	print(f'{num // gcd(num, den)} {den // gcd(num, den)}')


import math
t = int(input())
while t != 0:
	t -= 1
	(n, a, k) = list(map(int, input().split()))
	g = n * (n - 1)
	d = 360 * (n - 2) - 2 * a * n
	f = a * g + (k - 1) * d
	j = math.gcd(f, g)
	b = f // j
	e = g // j
	print(b, e)


import math
t = int(input())
while t > 0:
	t -= 1
	(n, a, k) = list(map(int, input().split()))
	Sn = (n - 2) * 180
	X = n * (n - 1) * a + 2 * (k - 1) * (Sn - a * n)
	Y = n * (n - 1)
	aa = math.gcd(X, Y)
	X //= aa
	Y //= aa
	print(X, Y)


import math
cases = input()
cases = int(cases)
for i in range(0, cases):
	(n, a, k) = map(int, input().split(' '))
	s = (n - 2) * 180
	numerator = int((2 * s - 2 * a * n) * (k - 1) + a * n * (n - 1))
	denominator = int(n * (n - 1))
	gcd = math.gcd(numerator, denominator)
	numerator = numerator / gcd
	denominator = denominator / gcd
	numerator = int(numerator)
	denominator = int(denominator)
	print(str(numerator) + ' ' + str(denominator))


def gcd(d, s):
	if s == 0:
		return d
	else:
		return gcd(s, d % s)
for _ in range(int(input())):
	(n, a, k) = [int(x) for x in input().split()]
	d = (360 * (n - 2) - 2 * a * n) * (k - 1)
	s = n * (n - 1)
	k = gcd(d, s)
	d = d // k
	s = s // k
	print(d + s * a, s)


import math
T = int(input())
for _ in range(T):
	(N, A, K) = map(int, input().split(' '))
	total = (N - 2) * 180
	diffT = total - N * A
	diffN = sum(range(1, N))
	r = A * diffN + (K - 1) * diffT
	d = math.gcd(r, diffN)
	while d > 1:
		r //= d
		diffN //= d
		d = math.gcd(r, diffN)
	print(r, diffN)


def find_gcd(n, m):
	max_num = max(n, m)
	min_num = min(n, m)
	modulo = max_num % min_num
	if max_num == 1 or modulo == 0:
		return min_num
	return find_gcd(min_num, modulo)
tests = int(input())
for _ in range(tests):
	(n, first, k) = [int(j) for j in input().split()]
	upper = n * (n - 1) * first + 2 * (k - 1) * (180 * (n - 2) - n * first)
	down = n * (n - 1)
	gcd = find_gcd(upper, down)
	print(upper // gcd, end=' ')
	print(down // gcd)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = int(input())
for i in range(t):
	temp = input().split()
	n = int(temp[0])
	a = int(temp[1])
	k = int(temp[2])
	tempn = (n - 2) * 180
	tempn = tempn * 2
	tempd = n
	tempn = tempn - 2 * a * tempd
	tempd = tempd * (n - 1)
	tempn = tempn * (k - 1) + a * tempd
	g = gcd(tempn, tempd)
	tempn /= g
	tempd /= g
	print(int(tempn), int(tempd))


from math import gcd
for _ in range(int(input())):
	(n, a, k) = map(int, input().split())
	b = 180 * (n - 2)
	if n % 2 == 1:
		c = n // 2
	else:
		c = n - 1
	d = b - n * a
	e = n * c
	if n % 2 == 0:
		d *= 2
	d = a * e + (k - 1) * d
	f = gcd(d, e)
	print(d // f, e // f)


from math import *
for i in range(int(input())):
	(n, a, k) = map(int, input().split())
	c = n * n - n
	c1 = 360 * (n - 2) - 2 * a * n
	c2 = a * c + (k - 1) * c1
	g = gcd(c2, c)
	print(c2 // g, c // g)


import math
t = int(input())
while t > 0:
	line = input()
	inp = [int(i) for i in line.split()]
	n = inp[0]
	a = inp[1]
	k = inp[2]
	total = (n - 2) * 180
	d_up = int(total - n * a)
	d_down = int(n * (n - 1) / 2)
	num = a * d_down + (k - 1) * d_up
	den = d_down
	gcd = math.gcd(num, den)
	print(str(int((a * d_down + (k - 1) * d_up) / gcd)) + ' ' + str(int(d_down / gcd)))
	t -= 1


import math
for _ in range(int(input())):
	(n, a, k) = map(int, input().split())
	num = 360 * (n - 2) - 2 * a * n
	d = n * (n - 1)
	num = a * d + (k - 1) * num
	print(int(num / math.gcd(num, d)), int(d / math.gcd(num, d)))


from math import gcd
t = int(input())
for i in range(t):
	(n, a, k) = map(int, input().split())
	p = a * n * (n - 1) + (k - 1) * (360 * (n - 2) - 2 * n * a)
	q = n * (n - 1)
	g = gcd(p, q)
	p //= g
	q //= g
	print(p, q)


def gcd(P, b):
	if b == 0:
		return P
	return gcd(b, P % b)
t = int(input())
for i in range(t):
	(n, P, k) = map(int, input().split())
	s = (n - 2) * 180
	ans = P + (k - 1) * (2 * s - 2 * P * n) // (n * (n - 1))
	x = P * n * (n - 1) + (k - 1) * 2 * (s - P * n)
	y = n * (n - 1)
	z = gcd(x, y)
	print(x // z, y // z)


def gcd(num1, s):
	if s == 0:
		return num1
	else:
		return gcd(s, num1 % s)
for i in range(int(input())):
	(n, a, k) = [int(x) for x in input().split()]
	num1 = (360 * (n - 2) - 2 * a * n) * (k - 1)
	s = n * (n - 1)
	k = gcd(num1, s)
	num1 = num1 // k
	s = s // k
	print(num1 + s * a, s)


import math
T = int(input())
for i in range(T):
	(n, a, k) = list(map(int, input().split()))
	Sn = (n - 2) * 180
	X = n * (n - 1) * a + 2 * (k - 1) * (Sn - a * n)
	Y = n * (n - 1)
	aa = math.gcd(X, Y)
	X //= aa
	Y //= aa
	print(X, Y)


from fractions import Fraction
for i in range(int(input())):
	(n, a, k) = map(int, input().split())
	t = (n - 2) * 180
	d = (2 * t / n - 2 * a) / (n - 1)
	o = a + (k - 1) * d
	f = Fraction(o).limit_denominator()
	print(f.numerator, f.denominator)


import math
for _ in range(int(input())):
	(n, a, k) = map(int, input().split())
	g = n * (n - 1)
	d = 360 * (n - 2) - 2 * a * n
	f = a * g + (k - 1) * d
	j = math.gcd(f, g)
	b = f // j
	e = g // j
	print(b, e)


from fractions import Fraction
for _ in range(int(input())):
	(n, a, k) = (int(i) for i in input().strip().split())
	sum_of_all_angles = 180 * (n - 2)
	common_diffrence_of_ap = 2 * (sum_of_all_angles - a * n) / (n * (n - 1))
	k_term = a + (k - 1) * common_diffrence_of_ap
	f = Fraction(k_term).limit_denominator()
	print(f.numerator, f.denominator, sep=' ')


def hcfnaive(a, b):
	if b == 0:
		return a
	else:
		return hcfnaive(b, a % b)
for i in range(int(input())):
	(N, A, K) = map(int, input().split())
	s = 180 * (N - 2)
	d = hcfnaive(A * N * (N - 1) + (s - N * A) * 2 * (K - 1), N * (N - 1))
	print((A * N * (N - 1) + (s - N * A) * 2 * (K - 1)) // d, N * (N - 1) // d)


import math
t = int(input())
for _ in range(t):
	(n, a, k) = [int(x) for x in input().split()]
	s = (n - 2) * 180
	num = 180 * (n - 2) * 2 - 2 * a * n
	num = a * n * (n - 1) + num * (k - 1)
	den = n * (n - 1)
	temp = math.gcd(num, den)
	while temp > 1:
		num = num // temp
		den = den // temp
		temp = math.gcd(num, den)
	print(num, den)


from sys import stdin, stdout
import math as m
input = stdin.readline
t = int(input().strip())
for _ in range(t):
	(n, a, k) = list(map(int, input().strip().split()))
	s = 180 * (n - 2)
	num = a * n * n - a * n + 2 * k * s - 2 * s - 2 * k * a * n + 2 * a * n
	den = n * (n - 1)
	gcd = m.gcd(num, den)
	num = num // gcd
	den = den // gcd
	print(num, den)


def gcd(a, b):
	if b > a:
		return gcd(b, a)
	elif b == 0:
		return a
	else:
		return gcd(b, a % b)
t = int(input())
for _ in range(t):
	(n, a, k) = map(int, input().split())
	num = a * n * (n - 1) + (k - 1) * (360 * (n - 2) - 2 * n * a)
	den = n * (n - 1)
	g = gcd(num, den)
	num = num // g
	den = den // g
	print(num, den)


from math import *
import sys

def input():
	return sys.stdin.readline().replace('\n', '').strip()
sys.setrecursionlimit(10 ** 9)

def gcd(a, b):
	if a > b:
		return gcd(b, a)
	if a == 0:
		return b
	return gcd(b % a, a)
for _ in range(int(input())):
	(n, a, k) = list(map(int, input().split()))
	num = a * n * (n - 1) + (k - 1) * 2 * (180 * (n - 2) - a * n)
	den = n * (n - 1)
	g = gcd(num, den)
	num //= g
	den //= g
	print(num, den)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
t = int(input())
for i in range(t):
	(n, a, k) = map(int, input().split(' '))
	add = 0
	x = 0
	y = 0
	add = 180 * (n - 2)
	x = a * (n * n) + a * n + 2 * add * k - 2 * a * n * k - 2 * add
	y = n * (n - 1)
	z = gcd(x, y)
	x = int(x / z)
	y = int(y / z)
	print(x, y)


from fractions import Fraction
for i in range(int(input())):
	a = [int(x) for x in input().split()]
	n = a[0]
	A = a[1]
	k = a[2]
	q = A + (k - 1) / (n - 1) * (360 * (n - 2) / n - 2 * A)
	x = 1
	if q - int(q) < 1 and q - int(q) > 0:
		o = Fraction(q).limit_denominator()
		print(o.numerator, o.denominator)
	else:
		print(int(q), 1)


def gcd(x, y):
	while y > 0:
		(x, y) = (y, x % y)
	return x
for _ in range(int(input())):
	(n, a, k) = map(int, input().split())
	xd = (180 - a) * n - 360
	d = int(n * (n - 1) / 2)
	x = a * d + (k - 1) * xd
	y = d
	g = gcd(x, y)
	print(x // g, y // g)


import math
for i in range(int(input())):
	(N, A, K) = map(int, input().split())
	num = 360 * (N - 2) - 2 * A * N
	S = N * (N - 1)
	num = A * S + (K - 1) * num
	print(int(num / math.gcd(num, S)), int(S / math.gcd(num, S)))


from math import gcd
t = int(input())
for i in range(t):
	(n, a, k) = map(int, input().split())
	s = 180 * (n - 2)
	if n % 2 == 1:
		c = n // 2
	else:
		c = n - 1
	d = s - n * a
	e = n * c
	if n % 2 == 0:
		d *= 2
	d = a * e + (k - 1) * d
	f = gcd(d, e)
	print(d // f, e // f)


def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)
for i in range(int(input())):
	(n, a, k) = map(int, input().split())
	x = (360 * (n - 2) - 2 * a * n) * (k - 1)
	y = n * (n - 1)
	k = gcd(x, y)
	x = x // k
	y = y // k
	print(x + y * a, y)


import sys
from collections import Counter, defaultdict, deque
from math import gcd, sqrt, ceil, log

def li():
	return [int(i) for i in sys.stdin.readline().split()]

def si():
	return sys.stdin.readline().split()

def ii():
	return int(sys.stdin.readline())

def ip():
	return input()
for tastcas in range(int(input())):
	(n, a, k) = li()
	x = a * n * (n - 1) + (k - 1) * (360 * (n - 2) - 2 * n * a)
	y = n * (n - 1)
	g = gcd(x, y)
	x //= g
	y //= g
	print(x, y)


import math as m
t = int(input())
for i in range(t):
	(n, a, k) = map(int, input().split())
	z = n * n - n
	d = 360 * (n - 2) - 2 * a * n
	c = a * z + (k - 1) * d
	g = m.gcd(c, z)
	print(c // g, z // g)


import math
from fractions import Fraction
case = int(input())
ans = []
for i in range(case):
	result = ''
	inp = input().split(' ')
	n = int(inp[0])
	a = int(inp[1])
	k = int(inp[2])
	y = (n - 1) * n
	d = 360 * n - 2 * a * n - 720
	x = a * y + (k - 1) * d
	b = math.gcd(x, y)
	x = str(x // b)
	y = str(y // b)
	result = x + ' ' + y
	ans.append(result)
print(*ans, sep='\n')