4

Square root (decimal)

Difficulty: EASY
Contributed By
Sounak Majumder
Avg. time to solve
10 min
Success Rate
90%

Problem Statement

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.

Input Format:
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.
Constraints:
1 <= T <= 10 ^ 4
1 <= N <= 10 ^ 15
1 <= D <= 6

Time limit: 1 sec.
Sample Input 1 :
2
1 6
10 3
Sample Output 1:
1.000000
3.162
Explanation to sample Input 1:
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 .
Sample input 2 :
2
12 6
20 1
Sample Output 2:
3.464101
4.4
Explanation to sample Input 2:
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 .
Reset Code
Full screen
copy-code
Console