maths.perfect_cube

Functions

perfect_cube(→ bool)

Check if a number is a perfect cube or not.

perfect_cube_binary_search(→ bool)

Check if a number is a perfect cube or not using binary search.

Module Contents

maths.perfect_cube.perfect_cube(n: int) bool

Check if a number is a perfect cube or not.

>>> perfect_cube(27)
True
>>> perfect_cube(4)
False

Check if a number is a perfect cube or not using binary search. Time complexity : O(Log(n)) Space complexity: O(1)

>>> perfect_cube_binary_search(27)
True
>>> perfect_cube_binary_search(64)
True
>>> perfect_cube_binary_search(4)
False
>>> perfect_cube_binary_search("a")
Traceback (most recent call last):
    ...
TypeError: perfect_cube_binary_search() only accepts integers
>>> perfect_cube_binary_search(0.1)
Traceback (most recent call last):
    ...
TypeError: perfect_cube_binary_search() only accepts integers