Sum of cubes#477

Sum of cubes (Editorial)

Notice that the number of cubes we'll deal with is O(\sqrt[3]{N}) , We should iterate from -O(\sqrt[3]{N}) to O(\sqrt[3]{N}) , let's define the bounds constant factor so we don't get WA verdict , in some negative cases you'll for sure exceed 1000^3 integers , so you should think about it , what's a safe constant overall , will be safe for sure.

And by considering iterating all pairs (-3000 \le x < y \le 3000) this will end up with O(1.8 \times 10^7) operations which is generally fast.

(It's possible to optimize to O(\sqrt[3]{N}) with few of a constant factor)

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double

void solve(){
    int n;cin>>n;
    for(int i=-3000;i<=3000;i++){
        for(int j=i;j<=3000;j++){
            if(i*i*i+j*j*j==n){
                cout<<i<<" "<<j<<"\n";
            }
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}