最大公约数or最小公倍数

最大公约数or最小公倍数

import org.junit.Test;

public class 最大公约数or最小公倍数 {
	public int maxGYS(int m,int n) {
		int temp = 0;
		if(m<n) {
			m = m^n;
			n = m^n;
			m = m^n;
		}
		while(m%n!=0) {
			temp = m%n;
			m = n;
			n = temp;
		}
		return n;
	}
	@Test
	public void test() {
		int a = 3;
		int b = 15;
		int maxGYS = maxGYS(a,b);
		int minGBS = a*b/maxGYS;
		System.out.println("最大公约数为: "+maxGYS);
		System.out.println("最小公倍数为: "+minGBS);
	}
}
原文地址:https://www.cnblogs.com/hgnulb/p/10092112.html