本文主要是介绍“辗转相除法”求最大公约数 ← 递归,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
【算法代码】
#include <bits/stdc++.h>
using namespace std;int gcd(int a,int b) {if(b==0) return a;else return gcd(b,a%b);
}int main() {int n;cin>>n;while(n--) {int a,b;cin>>a>>b;cout<<gcd(a,b)<<endl;}return 0;
}/*
in:
2
3 6
4 6out:
3
2
*/
【参考文献】
https://blog.csdn.net/hnjzsyjyj/article/details/136272280
https://blog.csdn.net/hnjzsyjyj/article/details/110733164
这篇关于“辗转相除法”求最大公约数 ← 递归的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!