結果

問題 No.2260 Adic Sum
ユーザー lam6er
提出日時 2025-03-20 19:00:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 437 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 82,600 KB
実行使用メモリ 185,600 KB
最終ジャッジ日時 2025-03-20 19:01:21
合計ジャッジ時間 6,318 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

n, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
max_diff = a[-1] - a[0]
ans = 0

current_power = p

while current_power <= max_diff:
    from collections import defaultdict
    mod_count = defaultdict(int)
    for num in a:
        mod = num % current_power
        mod_count[mod] += 1
    c_k = 0
    for cnt in mod_count.values():
        c_k += cnt * (cnt - 1) // 2
    ans += c_k
    next_power = current_power * p
    if next_power > max_diff:
        break
    current_power = next_power

print(ans)
0