Update appNew update is available. Click here to update.

Find Nth Root Of M

Contributed by
Anish De
Last Updated: 29 Mar, 2023
Easy
yellow-spark
0/40
Avg time to solve 10 mins
Success Rate 90 %
Share
91 upvotes

Problem Statement

You are given two positive integers N and M. You have to return the Nth root of M, i.e., M(1/N). If the Nth root is not an integer, return -1.

Note:
N'th root of an integer M is a number, which, when raised to the power N, gives M as a result.
Detailed explanation ( Input/output format, Notes, Images )
Constraints:
1 <= N <= 30
1 <= M <= 10^9

Time Limit: 1 sec.
Sample Input 1:
3 27
Sample Output 1:
3
Explanation For Sample Input 1:
3rd Root of 27 is 3, as (3)^3 equals 27.
Sample Input 2:
4 69
Sample Output 2:
-1
Explanation For Sample Input 2:
4th Root of 69 is not an integer, hence -1.
Reset Code
Full screen
Auto
copy-code
Console