辗转相除法(欧几里得算法)
#include
using namespace std;
#define LL long long
LL gcd(LL a, LL b){
return (a % b == 0) ? b : gcd(b, a % b);
}
LL x, y;
int main(){
cin >> x >> y;
cout << gcd(x, y);
return 0;
}
应用:
http://39.98.219.132:8080/problem/208
#include
using namespace std;
#define LL long long
LL gcd(LL a, LL b){
return (a % b == 0) ? b : gcd(b, a % b);
}
LL x, y;
int main(){
cin >> x >> y;
cout << gcd(x, y);
return 0;
}
应用:
http://39.98.219.132:8080/problem/208