【发布时间】:2017-06-09 02:56:07
【问题描述】:
编写一个方法,当传递两个正整数 m 和 n 时,如果 m 和 n 互质,则返回 true。当两个整数没有任何正整数公约数期望为 1 时,它们是互质数。
你可以假设m≤n。
public static boolean coPrime( int m, int n) {
if ( m%n == 0){
return true;
}
return false;
}
这是我目前所拥有的。 你怎么知道它们是互质的?
【问题讨论】:
-
return BigInteger.valueOf(m).gcd(BigInteger.valueOf(n)).equals(BigInteger.ONE);