Count pairs (a, b) with a³ + b³ = n. A double loop over both values works, but you can do better: fix one variable and solve for the other.
For each a with a³ ≤ n, the partner must satisfy b³ = n − a³. Compute b = round(cbrt(n − a³)), then verify b³ exactly with integers, so floating-point rounding can't fool you.
This fix one, derive the other pattern turns O(n²) searches into O(n) or better. You'll see it again in Two Sum.