每个测试文件均包含多组测试数据。第一行输入一个整数
代表数据组数,每组测试数据描述如下:
在一行上输入五个整数
代表
与
进行
运算,
分别代表加减乘除。
对于每一组测试数据,如果答案不存在,在一行上输出
;否则,在一行上输出两个整数,代表分数四则运算的分子分母,你需要确保输出的是最简分数。特别的,如果是非负分数,则不应当输出负号;如果是负分数,负号与分子一同输出。
5 1 2 1 1 2 1 2 2 1 2 -1 2 3 0 2 1 2 4 1 2 1 0 1 0 1
1 1 0 1 0 1 1 1 inf
对于第一组测试数据,列式为
;
对于第二组测试数据,列式为
;
对于第三组测试数据,列式为
;
对于第四组测试数据,列式为
。
import math
T = int(input())
res=[]
for _ in range(T):
a,b,op,c,d = map(int,input().split())
x,y=0,0
if b==0&nbs***bsp;d==0:
res.append("inf")
continue
if op==1:
x,y= a*d+c*b,b*d
elif op==2:
x,y= a*d-c*b,b*d
elif op==3:
x,y= a*c,b*d
else:
if c==0:
res.append("inf")
continue
x,y= a*d,c*b
if y<0:
y*=-1
x*=-1
g=math.gcd(x,y)
t = [x//g,y//g]
res.append(t)
for i in res:
if i[0]!="i":
print(*i)
continue
print("".join(i))