VOOZH about

URL: https://www.geeksforgeeks.org/dsa/nth-root-of-a-number-using-log/

⇱ Nth root of a number using log - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Nth root of a number using log

Last Updated : 12 Jul, 2025

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 find the Nth root of K.

Let D be our Nth root of the K, 
Then, 
Apply logK on both the sides - 
=> 
=> 
=> 
 

Below is the implementation of the above approach:  


Output: 
3.000000

 

Time Complexity: O(1)

Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: