結果

問題 No.800 四平方定理
コンテスト
ユーザー ikd
提出日時 2019-03-18 09:42:47
言語 Nim
(2.2.6)
コンパイル:
nim --nimcache=~ --hints:off -o:a.out -d:release cpp _filename_
実行:
./a.out
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 399 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,316 ms
コンパイル使用メモリ 69,880 KB
実行使用メモリ 66,432 KB
最終ジャッジ日時 2026-03-23 01:54:59
合計ジャッジ時間 4,267 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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