結果

問題 No.800 四平方定理
ユーザー ikd
提出日時 2019-03-18 09:42:47
言語 Nim
(2.2.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 399 bytes
コンパイル時間 3,350 ms
コンパイル使用メモリ 66,068 KB
実行使用メモリ 65,536 KB
最終ジャッジ日時 2024-07-01 22:39:06
合計ジャッジ時間 6,371 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils

proc main() =
  let
    nd = stdin.readLine.strip.split.map(parseInt)
    (n, d) = (nd[0], nd[1])

  var freq = newSeq[int64](n * n * 2 + 1)
  for x in 1..n:
    for y in 1..n:
      freq[x * x + y * y] += 1
  var ans: int64 = 0
  for z in 1..n:
    for w in 1..n:
      let v = w * w + d - z * z
      if v >= 0 and v < freq.len:
        ans += freq[v]
  echo ans
main()
0