import java.util.Scanner import scala.annotation.tailrec object Problem141 { def proc(m: Int, n: Int): Int = { @tailrec def magic(a: Int, b: Int, step: Int): Int = { (a, b) match { case (0, _) => step case _ if a % b == 0 => step + (a / b) - 1 case _ if a > b => magic(a % b, b, step + (a / b)) case _ if a < b => magic(b, a, step + 1) } } magic(m, n, 0) } def main(args: Array[String]) { val sc = new Scanner(System.in) val (m, n) = (sc.nextInt, sc.nextInt) val result = proc(m, n) println(result) } }