結果

問題 No.800 四平方定理
コンテスト
ユーザー yudedako
提出日時 2022-01-26 20:51:07
言語 Scala(Beta)
(3.8.2)
コンパイル:
scalac _filename_
実行:
/usr/bin/scala_run _class_
結果
AC  
実行時間 710 ms / 2,000 ms
コード長 416 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,956 ms
コンパイル使用メモリ 273,604 KB
実行使用メモリ 96,064 KB
最終ジャッジ日時 2026-03-09 19:33:41
合計ジャッジ時間 30,604 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import scala.annotation.tailrec
import scala.io.StdIn.*
import scala.math.*

@main def main =
  val Array(n, d) = readLine().split(' ').map(_.toInt)
  val factorCount = Array.fill(max(n * n * 2, d) + 1){0}

  for
    w <- 1 to n
    z <- 1 to w
  do
    factorCount(w * w - z * z) += 1

  var result = 0L
  for
    x <- 1 to n
    y <- 1 to n
  do
    result += factorCount(abs(d - x * x - y * y))

  println(result)
0