close
內容
給定兩個整數,請求出它們的最大公因數
輸入說明
輸入包含兩個整數,以空白鍵隔開,兩個整數均 大於 0, 小於 231
輸出說明
輸出兩個整數的最大公因數
範例輸入 #1
12 15
範例輸出 #1
3
範例輸入 #2
1 100
範例輸出 #2
1
C++:
#include <iostream> using namespace std; int GCD(int a,int b){ while(b!=0){ int t=b; b=a%b; a=t; } return a; } /**-----------------*/ int main() { ios::sync_with_stdio(0); cin.tie(0); int m,n; cin>>m>>n; cout<<GCD(m,n); return 0; }
文章標籤
全站熱搜