Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. import java.math.*;
  2. import java.util.*;
  3. import java.io.*;
  4.  
  5. public class Main {
  6. static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
  7. static PrintWriter out = new PrintWriter(System.out);
  8.  
  9. static String randomStr(){
  10. Random rand = new Random();
  11. int len = rand.nextInt(150) + 1;
  12. String res = "";
  13. for (int i=0;i<len;i++){
  14. res += (char)('0' + rand.nextInt(10));
  15. }
  16. return res;
  17. }
  18.  
  19. static void solve(){
  20. BigDecimal b = new BigDecimal(in.nextToken());
  21. BigDecimal L = BigDecimal.ZERO;
  22. BigDecimal R = b;
  23. BigDecimal ten = new BigDecimal("0.000000000000001");
  24. BigDecimal two = BigDecimal.valueOf(2);
  25. while ((R.subtract(L)).compareTo(ten) > 0) {
  26. BigDecimal mid = (L.add(R)).divide(two, 20, BigDecimal.ROUND_HALF_EVEN);
  27. if (((mid.multiply(mid)).multiply(mid)).compareTo(b) <= 0){
  28. L = mid;
  29. } else {
  30. R = mid;
  31. }
  32. }
  33. L = L.setScale(13, BigDecimal.ROUND_HALF_UP);
  34. L = L.setScale(10, BigDecimal.ROUND_FLOOR);
  35. String s = L.toString();
  36. int sum = 0;
  37. for (int i=0;i<s.length();i++){
  38. char ch = s.charAt(i);
  39. if ('0' <= ch && ch <= '9') {
  40. sum += ch - '0';
  41. }
  42. sum %= 10;
  43. }
  44. out.println(sum + " " + s);
  45. }
  46.  
  47. public static void main(String[] args) {
  48. int t = in.nextInt();
  49. for (int i=0;i<t;i++){
  50. solve();
  51. }
  52.  
  53. out.close();
  54. }
  55.  
  56. }
  57.  
  58. class Pair<F, S> {
  59. public final F first;
  60. public final S second;
  61.  
  62. public Pair(F first, S second) {
  63. this.first = first;
  64. this.second = second;
  65. }
  66.  
  67. @Override
  68. public boolean equals(Object o) {
  69. if (!(o instanceof Pair)) {
  70. return false;
  71. }
  72. Pair<?, ?> p = (Pair<?, ?>) o;
  73. return Objects.equals(p.first, first) && Objects.equals(p.second, second);
  74. }
  75.  
  76. @Override
  77. public int hashCode() {
  78. return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
  79. }
  80.  
  81. public static <A, B> Pair <A, B> create(A a, B b) {
  82. return new Pair<A, B>(a, b);
  83. }
  84. }
  85.  
  86. class FastReader {
  87.  
  88. BufferedReader bf;
  89. StringTokenizer tk = null;
  90. String DELIM = " ";
  91.  
  92. public FastReader(BufferedReader bf) {
  93. this.bf = bf;
  94. }
  95.  
  96. public void skipLine(){
  97. try {
  98. bf.readLine();
  99. } catch (Exception e) {
  100. throw new RuntimeException();
  101. }
  102. }
  103.  
  104. public String nextToken() {
  105. while (tk==null || !tk.hasMoreTokens()) {
  106. try {
  107. tk = new StringTokenizer(bf.readLine(), DELIM);
  108. } catch (Exception e){
  109. throw new RuntimeException();
  110. }
  111. }
  112. return tk.nextToken();
  113. }
  114.  
  115. public int nextInt() {
  116. try {
  117. return Integer.parseInt(nextToken());
  118. } catch (Exception e) {
  119. throw new RuntimeException();
  120. }
  121. }
  122.  
  123. public long nextLong() {
  124. try {
  125. return Long.parseLong(nextToken());
  126. } catch (Exception e) {
  127. throw new RuntimeException();
  128. }
  129. }
  130.  
  131. public double nextDouble() {
  132. try {
  133. return Double.parseDouble(nextToken());
  134. } catch (Exception e) {
  135. throw new RuntimeException();
  136. }
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement