結果

問題 No.3331 Consecutive Cubic Sum
コンテスト
ユーザー norioc
提出日時 2025-11-02 21:30:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,723 ms / 5,000 ms
コード長 576 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,108 KB
実行使用メモリ 188,592 KB
最終ジャッジ日時 2025-11-02 21:33:57
合計ジャッジ時間 46,074 ms
ジャッジサーバーID
(参考情報)
judge7 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate


def accum(a: list):
    acc = list(accumulate(a))
    return lambda l, r: acc[r] - (acc[l-1] if l > 0 else 0)


a = [pow(i, 3) for i in range(10**6+10)]
acc = accum(a)

N = int(input())
ans = []
for i in range(1, len(a)):
    if a[i] > N: break
    lo = i
    hi = len(a)-1
    while lo <= hi:
        m = (lo + hi) // 2
        x = acc(i, m)
        if x == N:
            ans.append((i, m))
            break
        elif x > N:
            hi = m - 1
        else:
            lo = m + 1

print(len(ans))
for l, r in ans:
    print(l, r)
0