#include<cstdio> #include<iostream> #include<cstdlib> #include<iomanip> #include<cmath> #include<cstring> #include<string> #include<algorithm> using namespace std; int a,b; int gcd(int a,int b) { if(b==0) return a; else return gcd(b,a%b); } int main() { cin>>a>>b; cout<<gcd(a,b); return 0; }
对于任意a,b∈N, b≠0,gcd(a,b)=gcd(b,a mod b)
复杂度 O(log(a+b)