結果

問題 No.800 四平方定理
ユーザー yudedako
提出日時 2022-01-26 20:51:07
言語 Scala(Beta)
(3.6.2)
結果
AC  
実行時間 1,247 ms / 2,000 ms
コード長 416 bytes
コンパイル時間 11,929 ms
コンパイル使用メモリ 256,964 KB
実行使用メモリ 94,772 KB
最終ジャッジ日時 2024-12-23 15:15:54
合計ジャッジ時間 43,813 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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