結果

問題 No.800 四平方定理
ユーザー 👑 obakyanobakyan
提出日時 2019-06-06 22:43:36
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 536 bytes
コンパイル時間 50 ms
コンパイル使用メモリ 6,812 KB
実行使用メモリ 68,212 KB
最終ジャッジ日時 2024-04-09 20:09:19
合計ジャッジ時間 2,503 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 45 ms
35,368 KB
testcase_11 AC 66 ms
68,204 KB
testcase_12 AC 62 ms
68,092 KB
testcase_13 AC 43 ms
35,412 KB
testcase_14 AC 57 ms
68,120 KB
testcase_15 AC 62 ms
68,164 KB
testcase_16 AC 58 ms
68,092 KB
testcase_17 AC 60 ms
68,128 KB
testcase_18 AC 70 ms
68,188 KB
testcase_19 AC 70 ms
68,200 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 69 ms
68,212 KB
testcase_23 AC 102 ms
68,092 KB
testcase_24 AC 92 ms
68,128 KB
testcase_25 AC 102 ms
68,024 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 93 ms
68,120 KB
testcase_29 AC 96 ms
68,032 KB
testcase_30 AC 93 ms
68,188 KB
testcase_31 AC 87 ms
68,024 KB
testcase_32 AC 93 ms
68,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local mmi = math.min

local n, d = io.read("*n", "*n")
local sq = {}
local box = {}
for i = 1, 2 * n * n do box[i] = 0 end
for i = 1, n do
  sq[i] = i * i
  box[2 * sq[i]] = 1
end
for i = 1, n - 1 do
  for j = i + 1, n do
    box[sq[i] + sq[j]] = box[sq[i] + sq[j]] + 2
  end
end
local cnt = 0
for w = 1, n do
  local w2d = d + sq[w]
  for z = 1, n do
    local tgt = w2d - sq[z]
    if tgt <= 0 then break
    elseif tgt <= 2 * n * n  then
      cnt = cnt + box[tgt]
    end
  end
end
print(cnt)
0