File tree 1 file changed +51
-0
lines changed
1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* Hacker Blocks */
2
+ /* Title - Kth Root */
3
+ /* Created By - Akash Modak */
4
+ /* Date - 25/06/2020 */
5
+
6
+ // You are given two integers n and k. Find the greatest integer x, such that, x^k <= n.
7
+
8
+ // Input Format
9
+ // First line contains number of test cases, T. Next T lines contains integers, n and k.
10
+
11
+ // Constraints
12
+ // 1<=T<=10 1<=N<=10^15 1<=K<=10^4
13
+
14
+ // Output Format
15
+ // Output the integer x
16
+
17
+ // Sample Input
18
+ // 2
19
+ // 10000 1
20
+ // 1000000000000000 10
21
+ // Sample Output
22
+ // 10000
23
+ // 31
24
+ // Explanation
25
+ // For the first test case, for x=10000, 10000^1=10000=n
26
+
27
+ #include < iostream>
28
+ #include < cmath>
29
+ using namespace std ;
30
+ int main () {
31
+ int t;
32
+ cin>>t;
33
+ while (t--){
34
+ long long int n,k;
35
+ cin>>n>>k;
36
+ long long int s=1 ,e=n;
37
+ long long int ans = 0 ;
38
+ while (s<=e){
39
+ long long int mid = (s+e)/2 ;
40
+ if (pow (mid,k)<=n){
41
+ ans = max (ans,mid);
42
+ s=mid+1 ;
43
+ }
44
+ else
45
+ e=mid-1 ;
46
+
47
+ }
48
+ cout<<ans<<endl;
49
+ }
50
+ return 0 ;
51
+ }
You can’t perform that action at this time.
0 commit comments