import scala.collection.immutable.IndexedSeq object Main { def sieve(n: Int): IndexedSeq[Int] = { val isNotPrime = scala.collection.mutable.BitSet(n + 1) for (i <- 2 to n) if (!isNotPrime(i)) for (j <- (i + i) to n by i) isNotPrime(j) = true return (2 to n).filter(!isNotPrime(_)) } def main(args: Array[String]): Unit = { val Array(l, h) = readLine.split(' ').map(_.toLong) val primes = sieve(110000).reverse for (p <- primes.map(_.toLong)) { if (l <= p * p && p * p <= h) { for (q <- primes) if (l <= p * q && p * q <= h) { println(p * q) return } } } val factorList = new Array[Int]((h - l).toInt + 1) for (p <- primes) for (i <- (Array(l - l % p, p + p).max - l).toInt to (h - l).toInt by p) if(0 <= i) factorList(i) = p println(factorList.zipWithIndex.max._2 + l) } }