Root

Interview

Time limit1sMemory limit128 MB

Summary
For each pair B and N, find the positive integer A that makes A^N as close to B as possible.
Level

Medium4 of 10

Topics
Binary search, Math, Brute force, Implementation
Solved
No attempts yet

Problem

Given positive integers BB and NN, write a program that finds the positive integer AA whose ANA^N is closest to BB. In other words, output the AA that minimizes ∣AN−B∣|A^N - B|. Note that ANA^N may be less than, equal to, or greater than BB.

Input

The input consists of several test cases. Each test case is a single line containing two integers BB and NN separated by a space. (1≤B≤1,000,0001 \le B \le 1{,}000{,}000, 1≤N≤91 \le N \le 9)

The last line of the input contains two zeros; this line is not processed.

Output

For each test case, output the corresponding AA on its own line.

Examples2

  1. Example 1

    Input
    4 3
    5 3
    27 3
    750 5
    1000 5
    2000 5
    3000 5
    1000000 5
    0 0
    
    Expected output
    1
    2
    3
    4
    4
    4
    5
    16
    
  2. Example 2

    Input
    50 2
    0 0
    
    Expected output
    7