結果

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

ソースコード

diff #

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

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

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

    vector<pair<ll, ll>> ans;
    for (ll i = 1; i * i * i <= n; i++){
        auto check = [&](ll mid)->bool {
            return cube_sum(mid) - cube_sum(i - 1) <= n;
        };
        ll ok = i, ng = 1000010;
        while (abs(ok - ng) > 1){
            ll mid = (ok + ng) / 2;
            if (check(mid)) ok = mid;
            else ng = mid;
        }
        if (cube_sum(ok) - cube_sum(i - 1) == n) ans.emplace_back(i, ok);
    }
    cout << ans.size() << endl;
    for (auto [x, y] : ans) cout << x << " " << y << endl;
}
0