You have been given two integers 'N' and 'D', Your task is to find the square root of the number 'N' with precision up to 'D' decimal places i.e. the difference between your answer and the correct answer should be less than 10 ^ (-D).
For example if N = 10 and D = 3, then your answer will be 3.162.
The first line of the input contains a single positive integer 'T', denoting the number of test cases.
The first line of each test case contains Two space-separated positive integers 'N' and 'D', denoting the number whose square root you have to find and the number of decimal places up to which you have to find the square root.
Output Format:
For each test case, print a single line containing a single number denoting the square root such that the difference between the number and the actual square root is less than or equal to 10 ^ (-D).
The output of each test case will be printed in a separate line.
Note:
You don't have to print anything, it has already been taken care of. Just Implement the given function.
1 <= T <= 10 ^ 4
1 <= N <= 10 ^ 15
1 <= D <= 6
Time limit: 1 sec.
2
1 6
10 3
1.000000
3.162
In the first test case the actual square root of 1 is 1.000000 and the answer is 1 so the difference between actual square root and the output is 0.000000 which is less than 10 ^ (-6) or 0.000001 .
In the second case the actual square root of 10 is 3.162277 and the output is 3.162 so the difference between the actual square root and the output is 0.000277 which is less than 10^(-3) or 0.001 .
2
12 6
20 1
3.464101
4.4
In the first test case the actual square root of 12 is 3.464101 and the output is 3.464101 so the difference between the actual square root and the output is 0.000000 which is less than or equal to 10^(-6) or 0.000001 .
In the first test case the actual square root of 20 is 4.472135 and the output is 4.4 so the difference between the actual square root and the output is 0.072135 which is less than 10^(-1) or 0.1 .
Check for all numbers using brute force.
O(sqrt(N)) where ‘N’ is the number that you want to find the square root of.
As we are traversing through all the number 1 to sqrt of ‘N’, the overall complexity is O(sqrt(N)).
O(1).
Since we are using constant extra memory.