結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー negistelnegistel
提出日時 2016-05-15 04:52:29
言語 Scala(Beta)
(3.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 891 bytes
コンパイル時間 4,967 ms
コンパイル使用メモリ 230,328 KB
最終ジャッジ日時 2024-04-27 02:20:48
合計ジャッジ時間 5,605 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
-- [E006] Not Found Error: Main.scala:12:22 ------------------------------------
12 |    val Array(l, h) = readLine.split(' ').map(_.toLong)
   |                      ^^^^^^^^
   |                      Not found: readLine
   |
   | longer explanation available when compiling with `-explain`
-- Warning: Main.scala:24:56 ---------------------------------------------------
24 |      for (i <- (Array(l - l % p, p + p).max - l).toInt to (h - l).toInt by p)
   |                                                        ^^
   |Alphanumeric method to is not declared infix; it should not be used as infix operator.
   |Instead, use method syntax .to(...) or backticked identifier `to`.
   |The latter can be rewritten automatically under -rewrite -source 3.4-migration.
-- Warning: Main.scala:24:73 ---------------------------------------------------
24 |      for (i <- (Array(l - l % p, p + p).max - l).toInt to (h - l).toInt by p)
   |                                                                         ^^
   |Alphanumeric method by is not declared infix; it should not be used as infix operator.
   |Instead, use method syntax .by(...) or backticked identifier `by`.
   |The latter can be rewritten automatically under -rewrite -source 3.4-migration.
2 warnings found
1 error found

ソースコード

diff #

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)
  }
}
0