val euc = new Function2[Int, Int, (Int, (Int, Int, Int))]{
private val chg = (x:Int, y:Int) => if(x > y) (x, y) else (y, x)
private val bas = new Function2[Int, Int, Int]{
def apply(x:Int, y:Int):Int = {
val t = chg(x, y)
if(t._1 % t._2 == 0) t._2 else apply(t._2, t._1 % t._2)
}
}
def apply(x:Int, y:Int):(Int, (Int, Int)) = {
val q = bas(x, y)
(q, (x/ q, y/ q))
}
}
0 件のコメント:
コメントを投稿