#20444: Python


howard20060216@gmail.com (Howard)

學校 : 臺北市私立薇閣高級中學
編號 : 106406
來源 : [140.113.124.238]
最後登入時間 :
2025-03-30 23:10:54

PYTHON 中的一個模組math.gcd()

 

#21391: Re:Python


10811124@stu.cmsh.khc.edu.tw (立峰陳)

學校 : 國立旗美高級中學
編號 : 108792
來源 : [27.240.168.65]
最後登入時間 :
2023-03-17 00:06:48

PYTHON 中的一個模組math.gcd()

 import math

a=input()
while a:
try:
b=a.split(' ')
b=[int(i) for i in b]
print(math.gcd(b[0],b[1]))
a=input()
except:
break
好像不太行欸......



#21392: Re:Python


asnewchien@gmail.com (david)

學校 : 南投縣立旭光高級中學
編號 : 68108
來源 : [114.42.176.221]
最後登入時間 :
2025-10-04 22:52:03

import sys

from math import gcd

 

for s in sys.stdin:

    a, b = map(int, s.split())

    r = .....

    print(r)

 

這樣有沒有清爽一點。

#23835: Re:Python


911091@stu.cchs.chc.edu.tw (莊明達)

學校 : 精誠中學
編號 : 134004
來源 : [111.246.12.50]
最後登入時間 :
2023-02-16 00:16:13

PYTHON 中的一個模組math.gcd()

 import math

a=input()
while a:
try:
b=a.split(' ')
b=[int(i) for i in b]
print(math.gcd(b[0],b[1]))
a=input()
except:
break
好像不太行欸......




縮行記得縮好!
import math
a=input()
while a:
  try:
    b=a.split(' ')
    b=[int(i) for i in b]
    print(math.gcd(b[0],b[1]))
    a=input()
  except:
    break;
還有其實可以更短
import math
while 1:
  try:
    x, y = [int(i) for i in input().split()]
    print(math.gcd(x, y))
  except:
    break;