![]() |
VOOZH | about |
Given the number N, the task is to find the cube root using the log function.
Examples:
Input: N = 8
Output: 2.000000
Input: N = 27
Output: 3.000000
Approach: To solve the problem mentioned above we will use log() function, according to the following formula:
Let cube root of N be d.
=> ?N = d
=> N(1/3) = d
Now, apply log on both sides:
log3 (N(1/3)) = log3 (d)
=> log3 (d) = 1/3 * log3 (N)
=> d = 3(1/3 * log3 (N))
Below is the implementation of the above problem:
2.00
Time complexity: O(log2(log3n))
Auxiliary space: O(1)