判断两个数之间是否互质

互质为求其最大公约数是否为1,如果为1的话之间互质。
任意两个不相等的质数互质。
经典欧几里得算法:


    private static boolean get(int n, int m) {//其函数为求最大公约数,当公约数为1的时候,则其互质
		// TODO Auto-generated method stub
		int t=0;
		while(m>0) {
			t=n%m;
			n=m;
			m=t;//当=0说明两个数之间存在倍数关系
		}
		if(n==1)return true;
		return false;
	}

猜你喜欢

转载自blog.csdn.net/So_Band/article/details/88078703