結果

問題 No.339 何人が回答したのか
ユーザー noriocnorioc
提出日時 2016-01-29 23:00:08
言語 Scala(Beta)
(3.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 425 bytes
コンパイル時間 6,066 ms
コンパイル使用メモリ 221,952 KB
最終ジャッジ日時 2023-09-11 23:15:53
合計ジャッジ時間 7,423 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

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

ソースコード

diff #

import math._

object Main {
  def gcd(a: Int, b: Int): Int = {
    if (b == 0) a
    else gcd(b, a % b)
  }

  def calc(xs: Array[Int]): Int = {
    if (xs.length == 1) return 1

    val g = xs.reduceLeft((a, b) => gcd(a, b))
    xs.map(_ / g).sum
  }

  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val xs = Array.fill(n)(sc.nextInt)

    println(calc(xs))
  }
}
0