#include <stdlib.h> #include <math.h> #include <iostream> using namespace std; int greatest_common_divisor1(int a,int b){ //辗转相减法 while(a!=b){ if(a>b) a=a-b; else b=b-a; } return a; } int greatest_common_divisor2(int a,int b){//辗转相除法 int c; while(b!=0){ c=a%b; a=b; b=c; } return a; } int main(){ int a,b,m,l; cin>>a>>b; l=greatest_common_divisor2(a,b); m=greatest_common_divisor1(a,b); cout<<"最大公约数:(辗转相减法)"<<m<<endl; cout<<"最大公约数:(辗转相除法)"<<l<<endl; cout<<"最小公倍数:"<<a*b/m; return 0; }