JAVA 고정 밀 소수 템 플 릿

5270 단어
 1 package   ;
 2 import java.math.BigDecimal;
 3 import java.math.BigInteger;
 4 import java.math.MathContext;
 5 import java.math.RoundingMode;
 6 import java.util.Scanner;
 7 import java.util.*;
 8 import java.io.*;
 9 public class Main {
10     public static void main(String [] args){
11         Scanner cin = new Scanner(System.in);
12         int T=cin.nextInt();
13         while(T>0){
14             //System.out.println(T);
15             MathContext mc = new MathContext(10, RoundingMode.HALF_DOWN);
16             BigDecimal n=cin.nextBigDecimal();
17             BigDecimal a=cin.nextBigDecimal();
18             
19             BigDecimal z1=BigDecimal.valueOf(1.0);
20             BigDecimal z2=BigDecimal.valueOf(2.0);
21             
22 
23             BigDecimal a2=a.multiply(z2,mc);
24             BigDecimal t1=z1.divide(a2,mc);
25             
26 
27             t1=t1.add(z1.divide(a,mc),mc);
28             
29             BigDecimal t2=z1.divide(t1,mc);
30             t1=t2.add(a,mc);
31             
32             t1=z1.divide(t1,mc);
33             
34             //System.out.println(t1);
35 
36             
37             BigDecimal ans=t1.multiply(n,mc);
38             
39             ans=z1.divide(ans,mc);
40             //ans=ans.setScale(10,BigDecimal.ROUND_DOWN);
41             System.out.println(ans);
42             T--;
43         }
44     }
45 }

좋은 웹페이지 즐겨찾기