結果

問題 No.3331 Consecutive Cubic Sum
コンテスト
ユーザー Vi24E
提出日時 2025-10-01 03:01:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 583 bytes
コンパイル時間 1,716 ms
コンパイル使用メモリ 198,848 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-02 21:10:59
合計ジャッジ時間 3,536 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

__int128_t cube_sum(__int128_t x){
    return (x * (x + 1) / 2) * (x * (x + 1) / 2);
}

int main() {
    ll n;
    cin >> n;
    assert(1 <= n && n <= 1000000000000000000);

    ll l = 1, r = 1;
    vector<pair<ll, ll>> ans;
    while (r * r * r <= n){
        __int128_t t = cube_sum(r) - cube_sum(l - 1);
        if (t == n){
            ans.push_back({l, r});
        }
        if (t <= n) r++;
        else l++;
    }
    cout << ans.size() << endl;
    for (auto [x, y] : ans) cout << x << " " << y << endl;
}
0