Kth Root [codingblocks]
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
Java Code:
IDE Code: https://ide.geeksforgeeks.org/VwbOuvQdfV
/* Amit Kumar 06-12-2020 IDE Code: https://ide.geeksforgeeks.org/VwbOuvQdfV */ package array; import java.util.Scanner; public class Array_KthRoot { public static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int testCase = scanner.nextInt(); while (testCase-- >0) { long n = scanner.nextLong(); int k = scanner.nextInt(); long head = 0; long tail = 1000000000000000L; long mid; long possibleAns=-1; while (head < tail) { mid = (head + tail)/2; if (Math.pow(mid, k) == n) { System.out.println("LOL"); possibleAns = mid; break; } if (Math.pow(mid, k) > n) { tail = mid-1; } else { possibleAns = mid; head = mid+1; } } System.out.println(possibleAns); } } }
decupXimpi Natalie Hall https://marketplace.visualstudio.com/items?itemName=consbepod-wo.Descargar-Bock-Bock-gratuita
ReplyDeleteliemethahu
subiXprop_re Travis Hill https://colab.research.google.com/drive/1MWYsT28bkbxPZUj34EoBzP0z-q-f-237
ReplyDeletedownload
link
download
ryevibando
amexin-go Erica Cain Software
ReplyDeleteDownload Free
scoutareshos