結果

問題 No.2260 Adic Sum
ユーザー shim0shim0
提出日時 2023-04-07 22:44:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,209 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 266,124 KB
最終ジャッジ日時 2024-04-15 23:57:23
合計ジャッジ時間 22,254 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
58,880 KB
testcase_01 AC 46 ms
60,800 KB
testcase_02 AC 46 ms
58,752 KB
testcase_03 AC 46 ms
59,520 KB
testcase_04 AC 57 ms
66,176 KB
testcase_05 AC 56 ms
66,176 KB
testcase_06 AC 55 ms
66,176 KB
testcase_07 AC 55 ms
66,816 KB
testcase_08 AC 86 ms
76,920 KB
testcase_09 AC 71 ms
76,160 KB
testcase_10 AC 84 ms
76,572 KB
testcase_11 AC 62 ms
71,040 KB
testcase_12 AC 84 ms
76,672 KB
testcase_13 AC 97 ms
77,052 KB
testcase_14 AC 458 ms
115,852 KB
testcase_15 AC 668 ms
159,676 KB
testcase_16 AC 398 ms
109,408 KB
testcase_17 AC 746 ms
174,264 KB
testcase_18 AC 747 ms
181,260 KB
testcase_19 AC 804 ms
190,724 KB
testcase_20 AC 910 ms
192,532 KB
testcase_21 AC 912 ms
189,484 KB
testcase_22 AC 944 ms
201,792 KB
testcase_23 AC 938 ms
131,972 KB
testcase_24 AC 753 ms
121,672 KB
testcase_25 AC 1,161 ms
256,924 KB
testcase_26 AC 1,099 ms
240,012 KB
testcase_27 AC 1,209 ms
266,124 KB
testcase_28 AC 1,167 ms
258,172 KB
testcase_29 AC 1,168 ms
258,920 KB
testcase_30 AC 1,101 ms
197,244 KB
testcase_31 AC 742 ms
161,932 KB
testcase_32 AC 746 ms
162,492 KB
testcase_33 AC 1,084 ms
252,596 KB
testcase_34 AC 961 ms
210,312 KB
testcase_35 AC 771 ms
167,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import factorial

n, p = map(int, input().split())
a = list(map(int, input().split()))

b = []
k = [[] for _ in range(40)]
for i in range(n):
    a_i = a[i]
    count = 0
    while a_i % p == 0:
        a_i //= p
        count += 1
    k[count].append(a[i])
    b.append(count)
b.sort()

ans = 0
for i in range(n):
    ans += b[i] * (n - (i + 1))
for i in range(40):
    for j in range(1, 40):
        num = p ** j
        k_dict = {}
        for k_num in k[i]:
            k_dict.setdefault(k_num // p ** i % num, 0)
            k_dict[k_num // p ** i % num] += 1
        for key, value in k_dict.items():
            ans += value * (value - 1) // 2

print(ans)
0