(C++/JAVA)欧几里得算法(辗转相除法)求两数最大公约数,最小公倍数(A*B/MAX)

(C++/JAVA)欧几里得算法(辗转相除法)求两数最大公约数 【(C++/JAVA)欧几里得算法(辗转相除法)求两数最大公约数,最小公倍数(A*B/MAX)】C++:

#include using namespace std; int oujilide(int m, int n) { int r = m%n; while (r != 0){ m = n; n = r; r = m%n; } return n; } int main(){ int m, n; cin >> m>>n; cout << oujilide(m,n); }

JAVA:
package dm; /** * * @author Lenovo */ public class DM { /** * @param args the command line arguments */ public static int oujilide(int m,int n){ int r=m%n; while(r!=0){ m=n; n=r; r=m%n; } return n; } public static void main(String[] args) { System.out.println(oujilide(10,8)); } }

    推荐阅读