10進で(ab)10と(bc)10という二つの自然数があり、それがbを消しても分数の値が同じなら、a < cならa / c、a > cならc / aを出力するだけです。
class Fraction(num :BigInt, den :BigInt) { val (numerator, denominator) = init(num, den) def init(num :BigInt, den :BigInt) = { val d = gcd(num, den).abs if(den > 0) (num / d, den / d) else (-num / d, -den / d) } def *(f :Fraction) = new Fraction(numerator * f.numerator, denominator * f.denominator) def *(n :BigInt) = new Fraction(numerator * n, denominator) def +(f :Fraction) = new Fraction(numerator * f.denominator + denominator * f.numerator, denominator * f.denominator) override def toString() = if(denominator != 1) numerator.toString + "/" + denominator.toString else numerator.toString def gcd(m :BigInt, n :BigInt) :BigInt = if(n == 0) m else gcd(n, m % n) } val it = for(a <- 1 to 9; b <- 1 to 9; c <- 1 to 9 if (10 * a + b) * c == (10 * b + c) * a && a != c) yield if(a < c) new Fraction(a, c) else new Fraction(c, a) println (it.reduceLeft(_ * _).denominator)