Skip to content

add precision_root_algorithm #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 3, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Misc/root_precision.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
Scanner scn = new Scanner(System.in);

int N = scn.nextInt();
int P = scn.nextInt();

System.out.println(squareRoot(N, P));
}

public static double squareRoot(int N, int P) {
double sqrt = 0;;

// Write your code here
double root = Math.pow(N, 0.5);
int pre = (int) Math.pow(10, P);
root = root * pre;
sqrt = (int)root;
return (double)sqrt/pre;
}
}