結果

問題 No.300 平方数
ユーザー くわいくわい
提出日時 2015-11-14 16:07:02
言語 Scala(Beta)
(3.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 764 bytes
コンパイル時間 5,503 ms
コンパイル使用メモリ 226,708 KB
最終ジャッジ日時 2024-04-27 02:15:38
合計ジャッジ時間 6,020 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
-- [E040] Syntax Error: Main.scala:27:32 ---------------------------------------
27 |  def main(args: Array[String]) {
   |                                ^
   |                                '=' expected, but '{' found
1 error found

ソースコード

diff #

import scala.annotation.tailrec
import scala.io.StdIn

object Problem300 {

  // 素因数分解
  def primeFactorization(n: Long): Seq[Long] = {
    @tailrec
    def factor(n: Long, div: Long, result: Seq[Long]): Seq[Long] = {
      if (n < div * div) {
        n +: result
      } else if (n % div == 0) {
        factor(n / div, div, div +: result)
      } else {
        factor(n, div + 1, result)
      }
    }
    factor(n, 2, Nil)
  }

  def proc(x: Long): Long = {
    val pf: Map[Long, Seq[Long]] = primeFactorization(x).groupBy(x => x)
    val oddPf: Map[Long, Seq[Long]] = pf.filter(_._2.length % 2 == 1)
    oddPf.keys.product
  }

  def main(args: Array[String]) {
    val x = StdIn.readLong()
    val result: Long = proc(x)
    println(result)
  }
}
0