I am creating a problem which requires me to find the cube root of certain numbers, some of them have whole number roots, but a lot of them don\'t.
I have numbers li
We first calculate a candidate integer of the cubit root by a very rough rounding (int(... + 0.1)
) then verify if it is really the cubic root or not with exact integer arithmetic. (I assumed n
is an int
)
cand = int(n ** (1.0/3.0) + 0.1)
if cand**3 == n:
print(cand, "is the cube root of ", n)
processing = False
else:
n -= 1