SDE Path

Nth Root of a Number Using Binary Search

Medium

Nth Root of a Number Using Binary Search

Given N and M, find the Nth root of M using binary search, or determine it does not exist as an integer.

Input format

A single line with N and M (N ≥ 1, M ≥ 1).

Output format

Print the integer Nth root of M if it is exact (r with r^N = M), otherwise -1.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
3 27
Expected output
3
Example 2
Input
4 69
Expected output
-1