Find Cube root of a number using Log function Last Updated : 14 Dec, 2022 Comments Improve Suggest changes Like Article Like Report Given the number N, the task is to find the cube root using the log function.Examples: Input: N = 8 Output: 2.000000Input: 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: C++ // C++ program to Find Cube root // of a number using Logarithm #include <bits/stdc++.h> // Function to find the cube root double cubeRoot(double n) { // calculate the cube root double ans = pow(3, (1.0 / 3) * (log(n) / log(3))); // Return the final answer return ans; } // Driver code int main() { double N = 8; printf("%.2lf ", cubeRoot(N)); return 0; } Java // Java program to Find Cube root // of a number using Logarithm class GFG{ // Function to find the cube root static double cubeRoot(double n) { // Calculate the cube root double ans = Math.pow(3, ((1.0 / 3) * (Math.log(n) / Math.log(3)))); // Return the final answer return ans; } // Driver code public static void main(String[] args) { double N = 8; System.out.printf("%.2f", cubeRoot(N)); } } // This code is contributed by Rajput-Ji Python3 # Python3 program to find cube root # of a number using logarithm import numpy as np # Function to find the cube root def cubeRoot(n): # Calculate the cube root ans = pow(3, (1.0 / 3) * (np.log(n) / np.log(3))) # Return the final answer return ans # Driver code N = 8 print("%.2f" % cubeRoot(N)) # This code is contributed by PratikBasu C# // C# program to find cube root // of a number using logarithm using System; class GFG{ // Function to find the cube root static double cubeRoot(double n) { // Calculate the cube root double ans = Math.Pow(3, ((1.0 / 3) * (Math.Log(n) / Math.Log(3)))); // Return the readonly answer return ans; } // Driver code public static void Main(String[] args) { double N = 8; Console.Write("{0:F2}", cubeRoot(N)); } } // This code is contributed by sapnasingh4991 JavaScript <script> // javascript program to Find Cube root // of a number using Logarithm // Function to find the cube root function cubeRoot( n) { // calculate the cube root let ans = Math.pow(3, (1.0 / 3) * (Math.log(n) / Math.log(3))); // Return the final answer return ans; } // Driver code let N = 8; document.write( cubeRoot(N).toFixed(2)); // This code is contributed by todaysgaurav </script> Output2.00 Time complexity: O(log2(log3n))Auxiliary space: O(1) Comment More infoAdvertise with us Next Article Find Cube root of a number using Log function S spp____ Follow Improve Article Tags : Mathematical Computer Science Fundamentals DSA maths-cube root +1 More Practice Tags : Mathematical Similar Reads Nth root of a number using log Given two integers N and K, the task is to find the Nth root of the K. Examples: Input: N = 3, K = 8 Output: 2.00 Explanation: Cube root of 8 is 2. i.e. 23 = 8 Input: N = 2, K = 16 Output: 4.00 Explanation: Square root of 16 is 4, i.e. 42 = 16 Approach: The idea is to use logarithmic function to fin 3 min read Square root of a number using log For a given number find the square root using log function. Number may be int, float or double. Examples: Input : n = 9Output : 3 Input : n = 2.93Output : 1.711724 We can find square root of a number using sqrt() method: C++ // C++ program to demonstrate finding // square root of a number using sqrt 3 min read Check if a number can be expressed as power | Set 2 (Using Log) Check if a number can be expressed as x^y (x raised to power y) Given a positive integer n, find if it can be expressed as x^y where y > 1 and x > 0. x and y both are integers.Examples : Input: n = 8 Output: true 8 can be expressed as 2^3 Input: n = 49 Output: true 49 can be expressed as 7^2 I 4 min read N-th root of a number Given two numbers n and m, find the n-th root of m. In mathematics, the n-th root of a number m is a real number that, when raised to the power of n, gives m. If no such real number exists, return -1.Examples: Input: n = 2, m = 9Output: 3Explanation: 32 = 9Input: n = 3, m = 9Output: -1Explanation: 3 9 min read Find minimum number of Log value needed to calculate Log upto N Given an integer N. The task is to find the minimum number of log values needed to calculate all the log values from 1 to N using properties of the logarithm.Examples: Input : N = 6 Output : 3 Value of log1 is already know, i.e. 0. Except this the three log values needed are, log2, log3, log5. Input 7 min read Like