結果

問題 No.1233 割り切れない気持ち
ユーザー 👑 obakyanobakyan
提出日時 2022-11-03 22:03:31
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 130 ms / 3,153 ms
コード長 959 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 5,292 KB
実行使用メモリ 25,180 KB
最終ジャッジ日時 2023-09-25 05:32:19
合計ジャッジ時間 7,909 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
22,944 KB
testcase_01 AC 63 ms
22,820 KB
testcase_02 AC 64 ms
22,880 KB
testcase_03 AC 64 ms
23,020 KB
testcase_04 AC 63 ms
22,908 KB
testcase_05 AC 63 ms
22,896 KB
testcase_06 AC 64 ms
23,044 KB
testcase_07 AC 76 ms
23,548 KB
testcase_08 AC 86 ms
23,968 KB
testcase_09 AC 114 ms
24,964 KB
testcase_10 AC 118 ms
25,116 KB
testcase_11 AC 75 ms
23,364 KB
testcase_12 AC 129 ms
24,928 KB
testcase_13 AC 129 ms
25,036 KB
testcase_14 AC 127 ms
25,048 KB
testcase_15 AC 130 ms
25,076 KB
testcase_16 AC 127 ms
25,008 KB
testcase_17 AC 106 ms
25,180 KB
testcase_18 AC 112 ms
24,908 KB
testcase_19 AC 111 ms
24,964 KB
testcase_20 AC 106 ms
24,904 KB
testcase_21 AC 110 ms
25,020 KB
testcase_22 AC 107 ms
24,992 KB
testcase_23 AC 108 ms
24,968 KB
testcase_24 AC 107 ms
24,996 KB
testcase_25 AC 107 ms
25,028 KB
testcase_26 AC 108 ms
25,028 KB
testcase_27 AC 110 ms
25,024 KB
testcase_28 AC 110 ms
25,060 KB
testcase_29 AC 111 ms
25,076 KB
testcase_30 AC 110 ms
24,928 KB
testcase_31 AC 110 ms
24,868 KB
testcase_32 AC 109 ms
24,968 KB
testcase_33 AC 111 ms
24,968 KB
testcase_34 AC 110 ms
24,940 KB
testcase_35 AC 110 ms
24,964 KB
testcase_36 AC 109 ms
25,020 KB
testcase_37 AC 64 ms
22,980 KB
testcase_38 AC 106 ms
25,056 KB
testcase_39 AC 110 ms
25,064 KB
testcase_40 AC 111 ms
25,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n = io.read("*n")
local t = {}
local lim = 200000
local cnt = {}
for i = 1, lim do
  t[i] = 0
  cnt[i] = 0
end
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
  t[a[i]] = t[a[i]] + a[i]
  cnt[a[i]] = cnt[a[i]] + 1
end
local sum = {t[1]}
local cntsum = {cnt[1]}
for i = 2, lim do
  sum[i] = sum[i - 1] + t[i]
  cntsum[i] = cntsum[i - 1] + cnt[i]
end
local ans = 0LL
for i = 2, lim do
  local mul = cnt[i]
  local j = 1
  while true do
    local left = (j - 1) * i
    local right = j * i - 1
    if lim < left then break end
    if lim < right then right = lim end
    local raw = sum[right]
    local c = cntsum[right]
    if 1 < left then
      raw = raw - sum[left - 1]
      c = c - cntsum[left - 1]
    end
    -- do
      -- print(i, j, raw, c * i * (j - 1) * mul,
      -- raw - c * i * (j - 1) * mul)
    -- end
    raw = (raw - c * i * (j - 1)) * mul
    ans = ans + raw
    j = j + 1
  end
end
ans = tostring(ans):gsub("LL", "")
print(ans)
0