結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー wattaiheiwattaihei
提出日時 2022-08-20 11:25:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 176 ms / 4,000 ms
コード長 697 bytes
コンパイル時間 499 ms
コンパイル使用メモリ 86,692 KB
実行使用メモリ 112,160 KB
最終ジャッジ日時 2023-08-22 11:33:42
合計ジャッジ時間 4,039 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,448 KB
testcase_01 AC 71 ms
71,108 KB
testcase_02 AC 70 ms
71,452 KB
testcase_03 AC 84 ms
76,100 KB
testcase_04 AC 84 ms
76,388 KB
testcase_05 AC 83 ms
76,424 KB
testcase_06 AC 83 ms
76,548 KB
testcase_07 AC 86 ms
76,652 KB
testcase_08 AC 106 ms
81,936 KB
testcase_09 AC 101 ms
81,684 KB
testcase_10 AC 101 ms
82,172 KB
testcase_11 AC 103 ms
82,164 KB
testcase_12 AC 103 ms
81,944 KB
testcase_13 AC 134 ms
91,948 KB
testcase_14 AC 128 ms
89,704 KB
testcase_15 AC 153 ms
97,348 KB
testcase_16 AC 152 ms
97,212 KB
testcase_17 AC 147 ms
95,248 KB
testcase_18 AC 137 ms
94,644 KB
testcase_19 AC 140 ms
95,792 KB
testcase_20 AC 176 ms
112,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().rstrip().split()))

M = max(A)+3

B = [0]*(M+1)
for a in A:
    B[a] += 1

C = [0]*(M+1)
D = [0]*(M+1)
for i in range(M):
    C[i+1] = C[i] + B[i+1]
    if B[i+1] == 1:
        D[i+1] = D[i] + i+1
    else:
        D[i+1] = D[i]

ans = 0
for x in range(1, M):
    if B[x] == 1:
        s = 0
        bucket_num = (M+1)//x
        for b in range(1, bucket_num+1):
            b_cnt = (C[x*(b+1)-1] if x*(b+1)-1 < M+1 else C[M]) - C[x*b-1]
            b_sum = (D[x*(b+1)-1] if x*(b+1)-1 < M+1 else D[M]) - D[x*b-1]
            r = b_cnt * x*(b+1) - b_sum
            s += r
        s -= x
        ans += s

print(ans)
0