結果

問題 No.3331 Consecutive Cubic Sum
コンテスト
ユーザー ococonomy1
提出日時 2025-11-02 21:38:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 87 ms / 5,000 ms
コード長 4,642 bytes
コンパイル時間 1,971 ms
コンパイル使用メモリ 202,032 KB
実行使用メモリ 21,592 KB
最終ジャッジ日時 2025-11-02 21:38:41
合計ジャッジ時間 7,968 ms
ジャッジサーバーID
(参考情報)
judge6 / judge8
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = __int128_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define MOD 998244353
//#define MOD 1000000007
#define el '\n'
#define El '\n'
#define YESNO(x) ((x) ? "Yes" : "No")
#define YES YESNO(true)
#define NO YESNO(false)
#define EXIT_ANS(x) {cout << (x) << '\n'; return;}
template <typename T> void inline SORT(vector<T> &v){sort(v.begin(),v.end()); return;}
template <typename T> void inline REV(vector<T> &v){reverse(v.begin(),v.end()); return;}
template <typename T> void inline VEC_UNIQ(vector<T> &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return;}
template <typename T> T inline MAX(vector<T> &v){return *max_element(v.begin(),v.end());}
template <typename T> T inline MIN(vector<T> &v){return *min_element(v.begin(),v.end());}
template <typename T> T inline SUM(vector<T> &v){T ans = 0; for(int i = 0; i < (int)v.size(); i++)ans += v[i]; return ans;}
template <typename T> void inline DEC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]--; return;}
template <typename T> void inline INC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]++; return;}
void inline TEST(void){cerr << "TEST" << endl; return;}
template <typename T> bool inline chmin(T &x,T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}
template <typename T> bool inline chmax(T &x,T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


// floor(sqrt(x))を整数で返す。にぶたんしているが幅が定数なので計算時間はO(1) にぶたん内で重い動作もない(代入、掛け算、ビットシフト、大小比較だけ)
long long ococo_floor_lsqrt(long long x) {

    // この仕様で嬉しいか?
    if(x < 0) {
        return -1;
    }
    if(x < INT_MAX / 2) {
        int ix = x;
        if(x == 0) return 0;
        if(x < 4) return 1;
        if(x < 9) return 2;

        int l = std::sqrt((double)x) - 2, r = std::sqrt((double)x) + 2;
        for(int i = l; i <= r + 1; i++) {
            if(i * i > ix) return i - 1;
        }
        return r + 1;
    }
    // doubleの仮数部が52bitでlong longが64bitだから差が12bitのため、誤差が2**12=4096を超えないんじゃないかと思ってこの範囲でにぶたんをしているが、
    // 全然これは嘘かもしれないので、めちゃくちゃ要検証である。
    // 一旦±10で見てダメそうだったら5000広げる方向性にした。これ以上の高速化が必要なパターンはあんまないだろうしこれでええやろ
    // とりあえずこのにぶたんは、sqrt(x)の答えが[l,r]のどこかにあるものとしている
    long long l = std::sqrt((double)x) - 10, r = std::sqrt((double)x) + 10;
    if(l * l > x) l -= 5000;
    if(r * r < x) r += 5000;

    if(l * l > x) l -= 5000 * 5000;
    if(r * r < x) r += 5000 * 5000;

    if(l * l > x) l -= 5000LL * 5000LL * 5000LL;
    if(r * r < x) r += 5000LL * 5000LL * 5000LL;
    while(r - l >= 2) {
        long long c = (r + l) >> 1;
        if(c * c <= x) l = c;
        else r = c;
    }
    for(long long i = l; i <= r + 1; i++) {
        if(i * i > x) return i - 1;
    }
    return r + 1;
}


#define MULTI_TEST_CASE false
void solve(void){
    //問題を見たらまず「この問題設定から言えること」をいっぱい言う
    //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
    //複数の解法のアイデアを思いついた時は全部メモしておく
    //g++ -D_GLIBCXX_DEBUG -Wall -O2 a.cpp -o o
    long long temp; cin >> temp;
    ll n = temp;
    vector<ll> v;
    v.push_back(0LL);
    for(int i = 1; i <= 1e6; i++){
        ll san = (ll)i * (ll)i * (ll)i;
        v.push_back(v.back() + san);
    }

    vector<pii> ans;
    for(int i = 0; i < (int)v.size(); i++){
        ll val = n + v[i];
        if(!binary_search(v.begin(),v.end(),val))continue;
        int idx = lower_bound(v.begin(),v.end(),val) - v.begin();
        ans.push_back(pair(i + 1,idx));
    }
    cout << (int)ans.size() << el;
    for(int i = 0; i < (int)ans.size(); i++){
        cout << ans[i].first << ' ' << ans[i].second << el;
    }
    return;
}

void calc(void){
    return;
}

signed main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE)cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
0