後來才發現原來最大公因數有內建
在algorithm 直接__gcd(a,b) 就好了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int a,b; while(cin>>a>>b && a && b){ if(b>a)swap(a,b); while(b){ a%=b; swap(a,b); } cout<<a<<'\n'; } } |
沒有留言:
張貼留言