一個畫面要有BlocState / BlocEvent / Bloc
我們先參考網路素材
while True:
try:
s1 = input() # 3 2
s1 = list(map(int, s1.split()))
# [3,2]
N = s1[0]
M = s1[1]
# data 為二維陣列結構
data = [
[3,2],
[1,5],
[6,4],
[1,1]
]
#3 2
#1 5
#6 4
#1 1
for i in range(0, N):# 0,1,2
# 每次讀取一橫排資料, 轉成 row 串列, 接著加入 data 串列
s2 = input()
row = list(map(int, s2.split())) # [1,5]
data.append(row)
S = 0
maxvalue = []
#[5,6,1] / 12
for i in range(0, N): #0 , 1 ,2
# 每組 row 之間的資料, 經排序後最後一個元素為最大值
data[i].sort() #0 : [1,5]
S = S+ data[i][M-1] #M 每一行有幾個數字
maxvalue.append(data[i][M-1]) #[5,6,1]
print(S,end='')#12
print()
#有沒有可整除s的數字
#maxvalue [5,6,1]
divisor_count =0
for i in range(0, N): # 0, 1 , 2
if S%maxvalue[i] == 0:
divisor_count +=1
print(maxvalue[i], end=' ')
if divisor_count == 0:
print("-1")
else:
print()
except:
break