b733. p018.求最大公因數 (GCD Function)
Tags : while循環 自定義函數
Accepted rate : 21人/27人 ( 78% ) [非即時]
評分方式:
Tolerant

最近更新 : 2026-07-12 15:44

Content

數學課學習了分數的約分。為了將分數約到最簡,需要求分子與分母的最大公因數。請編寫一個函數 gcd(a, b) 來計算並返回結果。

Input

輸入兩個正整數 a 和 b,以空格分隔。

Output

輸出一個整數,為 a 和 b 的最大公因數。

Sample Input #1
24 60
Sample Output #1
12
測資資訊:
記憶體限制: 512 MB
公開 測資點#0 (20%): 1.0s , <1K
公開 測資點#1 (20%): 1.0s , <1K
公開 測資點#2 (20%): 1.0s , <1K
公開 測資點#3 (20%): 1.0s , <1K
公開 測資點#4 (20%): 1.0s , <1K
Hint :
所學知識點:自定義函數 def、while 循環、輾轉相除法
Tags:
while循環 自定義函數
出處:
[管理者: ricky@g.puic...(wong ricky) ]


ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」