最大公約数(除算禁止)
Posted feedbacks - Scala
shiroさんと同じ方法で。
1 2 3 4 5 6 7 8 9 10 | import java.math.BigInteger
import java.math.BigInteger.ONE
implicit def int2big(n:int) = new BigInteger(n.toString)
def gcd(m:BigInteger, n:BigInteger):BigInteger = m.compareTo(n) match {
case 0 => n
case x if m == ONE || n == ONE => ONE
case 1 => gcd(n, m.subtract(n))
case x => gcd(m, n.subtract(m))
}
|





186 #4590() Rating0/8=0.00
あなたが使っている言語で除算と剰余が使えなくなりました。
以下の条件のもと最大公約数を求めるプログラムを書いてください。
条件
1 reply [ reply ]