Skip to content

Instantly share code, notes, and snippets.

@theArjun
Created March 22, 2019 11:39
Show Gist options
  • Select an option

  • Save theArjun/d751b50e9b42712e591c0459266d0a74 to your computer and use it in GitHub Desktop.

Select an option

Save theArjun/d751b50e9b42712e591c0459266d0a74 to your computer and use it in GitHub Desktop.
Hackerblocks Solution

You are given two integers n and k. Find the greatest integer x, such that, x^k <= n.


Input Format:

First line contains number of test cases, T. Next T lines contains integers, n and k.

Constraints:

1<=T<=10 1<=N<=10^15 1<=K<=10^4

Output Format:

Output the integer x


Sample Input:
2
10000 1
1000000000000000 10
Sample Output:
10000
31
Explanation:

For the first test case, for x=10000, 10000^1=10000=n

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k, result = 1;
long n = sc.nextLong();
k = sc.nextInt();
for (int x = 1; x <= n; x++) {
if (Math.pow(x, k) <= n) {
result = x;
} else {
break;
}
}
System.out.println("Answer : " + result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment