KTH ROOT
You are given two integers n and k. Find the greatest integer x, such that, x^k <= n.
how to solve ?
KTH ROOT
You are given two integers n and k. Find the greatest integer x, such that, x^k <= n.
how to solve ?
use Binary Search for x
#include
using namespace std;
int BinarySearch(int arr[],int n,int key){
int s=0;int e=n-1;
while (s<=e)
{
int mid=(s+e)/2;
if (arr[mid]==key)
return mid;
else if (arr[mid]<key){
e=mid-1;
}
else
{
s=mid+1;
}
}
return -1;
}
int main() {
int arr[10];
int n;
cin>>n;
after this what i have to do in kth root?
Understood now !!! …
How can we take n as long long? It is given that the highest value of n can be 10^12 which would overflow long long, right?
Akriti long long int can store digit upto 18 and if number is greater than 0 then u can also used unsigned it extend the limit
Heyy , actually int can store upto 10^9 and long long (or you say long long int ) can store upto 10^18