結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー mkawa2mkawa2
提出日時 2023-02-28 00:32:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 196 ms / 4,000 ms
コード長 1,194 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 109,784 KB
最終ジャッジ日時 2023-10-13 08:39:35
合計ジャッジ時間 3,749 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
79,300 KB
testcase_01 AC 85 ms
79,264 KB
testcase_02 AC 89 ms
79,108 KB
testcase_03 AC 102 ms
79,756 KB
testcase_04 AC 95 ms
79,676 KB
testcase_05 AC 102 ms
79,728 KB
testcase_06 AC 93 ms
79,804 KB
testcase_07 AC 100 ms
79,780 KB
testcase_08 AC 90 ms
79,996 KB
testcase_09 AC 90 ms
79,940 KB
testcase_10 AC 92 ms
80,024 KB
testcase_11 AC 91 ms
79,868 KB
testcase_12 AC 93 ms
79,776 KB
testcase_13 AC 136 ms
90,520 KB
testcase_14 AC 126 ms
87,868 KB
testcase_15 AC 151 ms
95,736 KB
testcase_16 AC 151 ms
95,792 KB
testcase_17 AC 140 ms
94,140 KB
testcase_18 AC 151 ms
93,644 KB
testcase_19 AC 142 ms
93,844 KB
testcase_20 AC 196 ms
109,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

# a>=b
# b-a%b
# b-(a-b*(a//b))
# b-a+b*(a//b)

mx = 200001
n = II()
aa = LI()

aa.sort()
ans = l = 0
cnt = [0]*mx
for i, a in enumerate(aa):
    cnt[a] += 1
    ans += l-a*i
    l += a

cs = [0]*(mx+1)
for i in range(mx): cs[i+1] = cs[i]+cnt[i]

for b in range(1, mx):
    if cnt[b] == 0: continue
    cur = -cnt[b]*(cnt[b]+1)//2
    for l in range(b, mx, b):
        r = min(l+b, mx)
        cur += cs[r]-cs[l]
        ans += cnt[b]*cur*l
        cur = 0

print(ans)
0