TLE in PERFECT CUBES(hacker-earth)

I have been trying to solve this question


And my approach is
https://www.hackerearth.com/submission/44226166/
But it gives a TLE verdict. Can anyone please suggest me an optimised solution for the same, as i cant understand the editorial thats mentioned with the problem.

Thanks.