close
問題描述:
給定二個正整數,利用輾轉相除法求其最大公因數。
輸入說明:
給定二個正整數
輸出說明:
輸出最大公因數
範例:
假設輸入為 300 與 250, 則輸出為 50
C++
#include <iostream>
using namespace std;
int main() {
int a,b;
while (cin>>a>>b)
{
while (b!=0)
{
int temp=b;
b=a%b;
a=temp;
}
cout<<a<<"\n";
}
return 0;
}
python
while True:
try:
n,m=map(int,input().split())
while m!=0:
temp=m
m=n%m
n=temp
print(n)
except:break
文章標籤
全站熱搜