Given two given numbers a and b where 1<= a <= b, find the perfect cubes between a and b (a and b inclusive).
Example 1:
Input: a = 1, b = 100
Output: 1 8 27 64
Explaination: These are the proper cubes between 
1 and 100.
Example 2:
Input: a = 24, b = 576
Output: 27 64 125 216 343 512
Explaination: These are the proper cubes between 
24 and 576.
Your Task:
You do not need to read input or print anything. Your task is to complete the function properCubes() which takes a and b as input parameters and returns the proper cubes between a and b. The function returns -1 if there is no proper cube between the given values.
Expected Time Complexity: O(cuberoot(b))
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ a ≤ b ≤ 10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def properCubes(self, a, b):
        # code here

Solutions:
import math

class Solution:

	def properCubes(self, a, b):
		r = math.floor(b ** (1 / 3))
		l = math.ceil(a ** (1 / 3))
		if (math.floor(b ** (1 / 3)) + 1) ** 3 == b:
			r += 1
		if l == r:
			return [l ** 3]
		if l > r:
			return [-1]
		ans = [i ** 3 for i in range(l, r + 1)]
		if not ans:
			ans.append(-1)
		return ans


import math

class Solution:

	def properCubes(self, a, b):
		d = a ** (1 / 3)
		d = math.ceil(d)
		e = d ** 3
		l = []
		while e <= b:
			l.append(e)
			d += 1
			e = d ** 3
		if len(l) == 0:
			return ['No']
		return l
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = [int(x) for x in input().split()]
		ob = Solution()
		ans = ob.properCubes(a, b)
		if len(ans) == 1 and ans[0] == -1:
			print('No')
		else:
			for it in ans:
				print(it, end=' ')
			print()


import numpy as np

class Solution:

	def properCubes(self, a, b):
		n = int(np.cbrt(b))
		x = []
		for i in range(1, n + 1):
			if i ** 3 >= a:
				x.append(i ** 3)
		if len(x) == 0:
			return [-1]
		else:
			return x