結果

問題 No.371 ぼく悪いプライムじゃないよ
コンテスト
ユーザー negistel
提出日時 2016-05-15 04:52:29
言語 Scala(Beta)
(3.8.1)
コンパイル:
scalac _filename_
実行:
java -cp .:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala3-library_3/3.8.1/scala3-library_3-3.8.1.jar:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala-library/3.8.1/scala-library-3.8.1.jar _class_
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 891 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,029 ms
コンパイル使用メモリ 235,068 KB
最終ジャッジ日時 2026-03-09 14:44:03
合計ジャッジ時間 7,424 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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 #
raw source code

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