標題:
公因數
[打印本頁]
作者:
tonyh
時間:
2022-4-23 16:33
標題:
公因數
raw=input("請依序輸入兩個正整數: ").split(" ")
a=int(raw[0]);
b=int(raw[1]);
smaller=min(a,b)
sum=0
print(a,"與",b,"的公因數有: ",end="")
for i in range(1,smaller+1):
if a%i==0 and b%i==0:
print(i,end=" ")
sum+=1
print("\n共有",sum,"個!")
複製代碼
作者:
郭詩瑜
時間:
2022-4-23 17:02
i = input("請輸入兩個整數並用空格隔開:")
i= i.split()
print(f"{i[0]}和{i[1]}的公因數有:",sep=" ",end="")
a =int(i[0])
b =int(i[1])
sum = 0
small = min(a,b)
for n in range(1, small + 1):
if (a%n == 0 and b%n == 0):
print(n,end=", ")
sum +=1
print(f"共有{sum}個")
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2