結果
| 問題 |
No.1233 割り切れない気持ち
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-11-03 22:03:31 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 106 ms / 3,153 ms |
| コード長 | 959 bytes |
| コンパイル時間 | 205 ms |
| コンパイル使用メモリ | 6,812 KB |
| 実行使用メモリ | 25,344 KB |
| 最終ジャッジ日時 | 2024-07-18 04:43:35 |
| 合計ジャッジ時間 | 5,959 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 |
ソースコード
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)