ACM中的java應用

1.java中大數類(包含大整數類和大浮點數類)常用函數:

函數:add, subtract, divide, mod, compareTo等,其中加減乘除模都要求是BigInteger(BigDecimal)和BigInteger(BigDecimal)之間的運算,所以需要把int(double)類型轉換爲BigInteger(BigDecimal),用函數BigInteger.valueOf().

BigInteger

將字符串轉換成BigInteger

BigInteger(String val)
          將 BigInteger 的十進制字符串表示形式轉換爲 BigInteger。

BigInteger(String val, int radix)
          將指定基數的 BigInteger 的字符串表示形式轉換爲 BigInteger。

BigInteger的加法

 BigInteger

add(BigInteger val)
          返回其值爲 (this + val) 的 BigInteger。

 BigInteger

and(BigInteger val)
          返回其值爲 (this & val) 的 BigInteger。

BigInteger的減法

BigInteger

subtract(BigInteger val)
          返回其值爲 (this - val) 的 BigInteger。

 BigInteger的乘法

 BigInteger

multiply(BigInteger val)
          返回其值爲 (this * val) 的 BigInteger。

 大數求餘:

 BigInteger

mod(BigInteger m)
          返回其值爲 (this mod m) 的 BigInteger。

大數除法

 BigInteger

divide(BigInteger val)
          返回其值爲 (this / val) 的 BigInteger。

 

其他一些

BigInteger

gcd(BigInteger val)
          返回一個 BigInteger,其值是 abs(this) 和 abs(val) 的最大公約數。

 

 BigInteger

max(BigInteger val)
          返回此 BigInteger 和 val 的最大值。

 BigInteger

min(BigInteger val)
          返回此 BigInteger 和 val 的最小值。

BigDecimal類

將字符串轉換成BigDecimal

BigDecimal(String val)
          將 BigDecimal 的字符串表示形式轉換爲 BigDecimal。

BigDecimal(String val,MathContext mc) 
          將 BigDecimal 的字符串表示形式轉換爲 BigDecimal,接受與 BigDecimal(String) 構造方法相同的字符串(按照上下文設置進行舍入)。

 兩個BigDecimal的相加

 BigDecimal

add(BigDecimal augend)
          返回一個 BigDecimal,其值爲 (this + augend),其標度爲 max(this.scale(), augend.scale())。

 BigDecimal

add(BigDecimal augend,MathContext mc) 
          返回其值爲 (this + augend) 的 BigDecimal(根據上下文設置進行舍入)。

 兩個BigDecimal的相減

 BigDecimal

subtract(BigDecimal subtrahend)
          返回一個 BigDecimal,其值爲 (this - subtrahend),其標度爲 max(this.scale(), subtrahend.scale())。

 BigDecimal

subtract(BigDecimal subtrahend,MathContext mc) 
          返回其值爲 (this - subtrahend) 的 BigDecimal(根據上下文設置進行舍入)。

兩個BigDecimal的相除:

 BigDecimal

divide(BigDecimal divisor)
          返回一個 BigDecimal,其值爲 (this / divisor),其首選標度爲 (this.scale() - divisor.scale());如果無法表示準確的商值(因爲它有無窮的十進制擴展),則拋出 ArithmeticException。

 BigDecimal

divide(BigDecimal divisor, int roundingMode)
          返回一個 BigDecimal,其值爲 (this / divisor),其標度爲 this.scale()。

 BigDecimal

divide(BigDecimal divisor, int scale, int roundingMode)
          返回一個 BigDecimal,其值爲 (this / divisor),其標度爲指定標度。

 BigDecimal

divide(BigDecimal divisor, int scale,RoundingMode roundingMode) 
          返回一個 BigDecimal,其值爲 (this / divisor),其標度爲指定標度。

 BigDecimal

divide(BigDecimal divisor,MathContext mc) 
          返回其值爲 (this / divisor) 的 BigDecimal(根據上下文設置進行舍入)。

 BigDecimal

divide(BigDecimal divisor,RoundingMode roundingMode) 
          返回一個 BigDecimal,其值爲 (this / divisor),其標度爲 this.scale()。

 計算BigDecimal的N次冪

BigDecimal

pow(int n) 
          返回其值爲 (thisn) 的 BigDecimal,準確計算該冪,使其具有無限精度。

 BigDecimal

pow(int n, MathContext mc) 
          返回其值爲 (thisn) 的 BigDecimal。

 有關轉換成字符串的方法

 String

toEngineeringString() 
          返回此 BigDecimal 的字符串表示形式,需要指數時,則使用工程計數法。

 String

toPlainString() 
          返回不帶指數字段的此 BigDecimal 的字符串表示形式。

 String

toString() 
          返回此 BigDecimal 的字符串表示形式,如果需要指數,則使用科學記數法。

2.一些java常規操作總結:

1.一、基本函數:  
2.1.valueOf(parament); 將參數轉換爲制定的類型  
3.  比如 int a=3;  
4.       BigInteger b=BigInteger.valueOf(a);  
5.     則b=3;  
6.       String s="12345";  
7.       BigInteger c=BigInteger.valueOf(s);  
8.     則c=12345;  
9. 2.add(); 大整數相加  
10.   BigInteger a=new BigInteger("23");  
11.   BigInteger b=new BigInteger("34");  
12.   a. add(b);  
13.3.subtract(); 相減  
14.4.multiply(); 相乘  
15.5.divide();    相除取整  
16.6.remainder();取餘  
17.7.pow();   a.pow(b)=a^b  
18.8.gcd();   最大公約數  
19.9.abs(); 絕對值  
20.10.negate();取反數  
21.11.mod(); a.mod(b)=a%b=a.remainder(b);  
22.12.max(); min();  
23.13.punlic int comareTo();  
24.14.boolean equals(); 是否相等  
25.15.BigInteger構造函數:  
26.  一般用到以下兩種:  
BigInteger(String val); //指定字符串轉換爲十進制表示形式;  
27.   BigInteger(String val,int radix);   //將指定基數的BigInteger的字符串表示形式轉換爲BigInteger  
28.Ⅱ.基本常量:  
29.   A=BigInteger.ONE    1  
30.   B=BigInteger.TEN    10  
31.   C=BigInteger.ZERO   0  
32.Ⅲ.基本操作  
33.1.   讀入:  
34.用Scanner類定義對象進行控制檯讀入,Scanner類在java.util.*包中  
35.
36.     Scanner cin=new Scanner(System.in);// 讀入  
37.     while(cin.hasNext())   //等同於!=EOF  
38.    {  
39.        int n;  
40.        BigInteger m;    
41.        n=cin.nextInt(); //讀入一個int;  
42.        m=cin.BigInteger();//讀入一個BigInteger;  
43.        System.out.print(m.toString());  
44.    }  
45.Ⅳ.運用  
46.四則預算:  
47.import java.util.Scanner;  
48.import java.math.*;  
49.import java.text.*;  
50.public class Main   
51.{  
52.public static void main(String args[])  
53.{  
54.   Scanner cin = new Scanner ( System.in );  
55.   BigInteger a,b;  
56.   int c;  
57.   char op;  
58.   String s;  
59.    
60.   while( cin.hasNext() )  
61.   {  
62.    a = cin.nextBigInteger();  
63.    s = cin.next();  
64.    op = s.charAt(0);  
65.    if( op == '+')  
66.    {  
67.     b = cin.nextBigInteger();  
68.     System.out.println(a.add(b));  
69.    }  
70.    else if( op == '-')  
71.    {  
72.     b = cin.nextBigInteger();  
73.     System.out.println(a.subtract(b));  
74.    }  
75.    else if( op == '*')  
76.    {   b = cin.nextBigInteger();  
77.     System.out.println(a.multiply(b));  
78.    }  
79.    else  
80.    {   BigDecimal a1,b1,eps;  
81.     String s1,s2,temp;  
82.     s1 = a.toString();  
83.       a1 = new BigDecimal(s1);  
84.     b = cin.nextBigInteger();  
85.     s2 = b.toString();  
86.     b1 = new BigDecimal(s2);  
87.     c = cin.nextInt();  
88.     eps = a1.divide(b1,c,4);  
89.     //System.out.println(a + " " + b + " " + c);  
90.      //System.out.println(a1.doubleValue() + " " + b1.doubleValue() + " " + c);  
91.     System.out.print( a.divide(b) + " " + a.mod(b) + " ");  
92.     if( c != 0)  
93.     { temp = "0.";  
94.      for(int i = 0; i < c; i ++) temp += "0";  
95.      DecimalFormat gd = new DecimalFormat(temp);  
96.      System.out.println(gd.format(eps));  
97.     }  
98.     else System.out.println(eps);  
99.    }  
100.   }  
101.   }  
102.}
103.    import java.io.* import java.util.*   
104.    public class Main {   
105.         public static void main(String args[])   
106.        {   Scanner cin = 
new Scanner(new BufferedInputStream(System.in));       
107.        }   
108.    }    
109.  也可以直接 Scanner cin = new Scanner(System.in); 
110.                                  加Buffer可能會快一些。  
111.         讀一整行: String s = cin.nextLine();     
112.          //相當於   gets(s);  或 cin.getline(...);  判斷   是否有下一個輸入可以用 cin.hasNext() 或 cin.hasNextInt()     或 cin.hasNextDouble()  
113.(3) 輸出一般可以直接用 System.out.print() 和 System.out.println(),前者不輸出換行,而後者輸出。   
114.System.out.println(n);   // n 爲 int 型 同一行輸出多個整數可以用     
System.out.println(new Integer(n).toString() + " " + new Integer(m).toString());   
//也可重新定義:   
115.static PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));       
116.cout.println(n);   
117.(4)對於輸出浮點數保留幾位小數的問題,可以使用DecimalFormat類,   
118.import java.text.*;   
119.//規格化的輸出:
函數:這裏0指一位數字,#指除0以外的數字(如果是0,則不顯示),四捨五入.
120.    DecimalFormat f = new DecimalFormat("#.00#");   
121.    DecimalFormat g = new DecimalFormat("0.000");   
122.    double a = 123.45678, b = 0.12;   
123.    System.out.println(f.format(a));   
124.    System.out.println(f.format(b));   
125.    System.out.println(g.format(b));   
126.大數:  
127.BigInteger 和 BigDecimal 是在java.math包中已有的類,前者表示整數,後者表示浮點數   
128.import java.math.*  // 需要引入 java.math 包   
129.BigInteger a = BigInteger.valueOf(100);   
130.BigInteger b = BigInteger.valueOf(50);   
131.BigInteger c = a.add(b)   // c = a + b;   
132.  
133.//主要有以下方法可以使用:   
134.BigInteger add(BigInteger other)   
135.BigInteger subtract(BigInteger other)   
136.BigInteger multiply(BigInteger other)   
137.BigInteger divide(BigInteger other)   
138.BigInteger mod(BigInteger other)   
139.int compareTo(BigInteger other)   
140.static BigInteger valueOf(long x)   
141.//輸出數字時直接使用 System.out.println(a) 即可  
142.字符串:  
143.String 類用來存儲字符串,可以用charAt方法來取出其中某一字節,  計數從0開始:  
144.String a = "Hello";    // a.charAt(1) = 'e'  
145.用substring方法可得到子串,如上例  
146.System.out.println(a.substring(0, 4))     // output "Hell"  
147.注意第2個參數位置上的字符不包括進來。這樣做使得 s.substring(a, b) 總是有 b-a個字符。  
148.字符串連接可以直接用 + 號,如  
149.String a = "Hello";   
150.String b = "world";   
151.System.out.println(a + ", " + b + "!");    // output "Hello, world!"  
如想直接將字符串中的某字節改變,可以使用另外的StringBuffer類。  
152.調用遞歸(或其他動態方法)  
153.在主類中 main 方法必須是 public static void 的,在 main 中調用非static類時會有警告信息,   
154.可以先建立對象,然後通過對象調用方法:  
155.public class Main {            
156.    void dfs(int a)   
157.    {      if () return;    
158.             dfs(a+1);   
159.    }   
160.    public static void main(String args[])   
161.    {    Main e = new Main();   
162.              e.dfs(0);   }   
163.}    
164.其他注意的事項:  
165.(2) Java 裏的數組有些變動,多維數組的內部其實都是指針,所以Java不支持fill多維數組。   
(3) 布爾類型爲 boolean,只有true和false二值,在 if (...) / while (...) 等語句的條件中必須爲boolean類型。   
在C/C++中的 if (n % 2) ... 在Java中無法編譯通過。  
166.(4) 下面在java.util包裏Arrays類的幾個方法可替代C/C++裏的 memset、qsort/sort 和 bsearch:  
167.Arrays.fill()   
168.Arrays.sort()   
169.Arrays.binarySearch()     
170.  

 3.java中常用方法:

a. 字符串處理

java中字符串String是不可以修改的,要修改只能轉換爲字符數組.

例程:

import java.io.*;

import java.math.*;

import java.util.*;

import java.text.*;

public class Main

{   public static void main(String[] args)

    {   int i;

       Scanner cin =

new Scanner (new BufferedInputStream(System.in));

        String st = "abcdefg";

        System.out.println(st.charAt(0));

// st.charAt(i)就相當於st[i].

        char [] ch;

       ch = st.toCharArray(); // 字符串轉換爲字符數組.

        for (i = 0; i < ch.length; i++) ch[i] += 1;

        System.out.println(ch); // 輸入爲“bcdefgh.

if (st.startsWith("a")) // 如果字符串以'0'開頭.

        {  st = st.substring(1);

// 從第1位開始copy(開頭爲第0). }

    }

}

b. 進制轉換

java很強大的一個功能。

函數:

String st = Integer.toString(num, base); // num當做10進制的數轉成base進制的st(base <= 35).

int num = Integer.parseInt(st, base); // st當做base進制,轉成10進制的int(parseInt有兩個參數,第一個爲要轉的字符串,第二個爲說明是什麼進制).   

BigInter m = new BigInteger(st, base); // st是字符串,basest的進制.

1.如果要將一個大數以2進制形式讀入 可以使用cin.nextBigInteger(2);

當然也可以使用其他進制方式讀入;

2.如果要將一個大數轉換成其他進制形式的字符串 使用cin.toString(2);//將它轉換成2進製表示的字符串

例程:POJ 2305

import java.io.*;

import java.util.*;

import java.math.*;

public class Main

{   public static void main(String[] args)

    {    int b;

        BigInteger p,m,ans;

        String str ;

        Scanner cin = new Scanner (new BufferedInputStream(System.in));

        while(cin.hasNext())

        {   b=cin.nextInt();

            if(b==0)

                break;

            p=cin.nextBigInteger(b);

            m=cin.nextBigInteger(b);

ans=p.mod(m);

            str=ans.toString(b);

            System.out.println(str);

        }

    }

}

c. 排序

函數:Arrays.sort()

例程:

import java.io.*;

import java.math.*;

import java.util.*;

import java.text.*;

public class Main

{   

public static void main(String[] args)

    {  Scanner cin = new Scanner (new BufferedInputStream(System.in));

        int n = cin.nextInt();

        int a[] = new int [n];

        for (int i = 0; i < n; i++) a[i] = cin.nextInt();

        Arrays.sort(a);

       for (int i = 0; i < n; i++) System.out.print(a[i] + " ");

    }

}

d. 結構體排序:

例子:一個結構體有兩個元素String xint y,排序,如果x相等y升序,否者x升序。

一、Comparator

強行對某個對象collection進行整體排序的比較函數,可以將Comparator傳遞給Collections.sortArrays.sort

接口方法:這裏也給出了兩種方法,

import java.util.*;

class structSort{

    String x;

    int y;

}

class cmp implements Comparator<structSort>{

public int compare(structSort o1, structSort o2) {

if(o1.x.compareTo(o2.x) == 0){

//這個相當於c/c++strcmpo1.x , o2,x

return o1.y - o2.y;

}

return o1.x.compareTo(o2.x);

}

}

public class Main {

public static void main(String[] args) {

 Comparator<structSort> comparator =

newComparator<structSort>(){

public int compare(structSort o1, structSort o2) {

if(o1.x.compareTo(o2.x) == 0){

return o1.y - o2.y;}

return o1.x.compareTo(o2.x);  }

 };

 Scanner cin = new Scanner(System.in);

 int n = cin.nextInt();

 structSort a[] = new structSort[10];

 for (int i = 0; i < n; i++) {

a[i] = new structSort();

a[i].x = cin.next();

a[i].y = cin.nextInt(); 

}

 Arrays.sort(a,0,n,comparator);

//這個直接使用Comparator

 Arrays.sort(a,0,n,new cmp());

//這個實現Comparator,就就跟c++中的sort函數調用就差不多了

 for (int i = 0; i < n; i++) {

System.out.println(a[i].x+" "+a[i].y);

}

}

e.Comparable

強行對實現它的每個類的對象進行整體排序,實現此接口的對象列表(和數組)可以通過Collections.sortArrays.sort進行自動排序。就是輸入完了直接就默認排序了,

接口方法:

import java.util.*;

class structSort implements Comparable<structSort>{

    String x;

    int y;

    public int compareTo(structSort o1) {

if(this.x.compareTo(o1.x) == 0){

return this.y - o1.y;}

return this.x.compareTo(o1.x);

}

}

public class Main {

public static void main(String[] args) {

 Scanner cin = new Scanner(System.in);

 int n = cin.nextInt();

 structSort a[] = new structSort[10];

 for (int i = 0; i < n; i++) {

a[i] = new structSort();

a[i].x = cin.next();

a[i].y = cin.nextInt();}

 Arrays.sort(a,0,n);

 for (int i = 0; i < n; i++) {

System.out.println(a[i].x+" "+a[i].y);}

}

}

f.Java進制轉換集錦

java中進行二進制,八進制,十六進制,十進制間進行相互轉換       

Integer.toHexString(int i)//十進制轉成十六進

Integer.toOctalString(int i) //十進制轉成八進制

Integer.toBinaryString(int i)//十進制轉成二進制

Integer.valueOf("FFFF",16).toString()

//十六進制轉成十進制

Integer.valueOf("876",8).toString()

//八進制轉成十進制

Integer.valueOf("0101",2).toString()

//二進制轉十進制

至於轉換成二進制或其他進制,以字符aASCII爲例:

int i = 'a';

String iBin = Integer.toBinaryString(i);//二進制

String iHex = Integer.toHexString(i);//十六進制

String iOct = Integer.toOctalString(i);//八進制

String iWoKao = Integer.toString(i,3);//三進制或任何你想要的35進制以下的進制

有什麼方法可以直接將2,8,16進制直接轉換爲10進制的嗎?

java.lang.IntegerparseInt(String s, int radix)

使用第二個參數指定的基數,將字符串參數解析爲有符號的整數。

examples from jdk:

parseInt("0", 10) returns 0

parseInt("473", 10) returns 473

parseInt("-0", 10) returns 0

parseInt("-FF", 16) returns -255

parseInt("1100110", 2) returns 102

parseInt("2147483647", 10) returns 2147483647

parseInt("-2147483648", 10) returns -2147483648

parseInt("2147483648",10)

throwsaNumberFormatException

parseInt("99", 8) throws a NumberFormatException

parseInt("Kona", 10) throws a NumberFormatException

parseInt("Kona", 27) returns 411787

進制轉換如何寫(二,八,十六)不用算法

Integer.toBinaryString;Integer.toOctalString

Integer.toHexString

例:

public class Test{

public static void main(String args[]){

   int i=100;

   String binStr=Integer.toBinaryString(i);

   String otcStr=Integer.toOctalString(i);

   String hexStr=Integer.toHexString(i);

   System.out.println(binStr);

各種數字類型轉換成字符串型:

String s = String.valueOf( value);

// 其中 value 爲任意一種數字類型。

字符串型轉換成各種數字類型:

String s = "169";

byte b = Byte.parseByte( s );

short t = Short.parseShort( s );

int i = Integer.parseInt( s );

long l = Long.parseLong( s );

Float f = Float.parseFloat( s );

Double d = Double.parseDouble( s );


g. 數字類型與數字類對象之間的轉換:

byte b = 169;

Byte bo = new Byte( b );

b = bo.byteValue();

short t = 169;

Short to = new Short( t );

t = to.shortValue();

int i = 169;

b = bo.byteValue();

short t = 169;

Short to = new Short( t );

t = to.shortValue();

int i = 169;

Integer io = new Integer( i );

i = io.intValue();

long l = 169;

Long lo = new Long( l );

l = lo.longValue();

float f = 169f;

Float fo = new Float( f );

f = fo.floatValue();

double d = 169f;

Double dObj = new Double( d );

d = dObj.doubleValue();


4.java大數基礎題目

//大數階乘
import java.math.BigInteger;
import java.util.Scanner;
public class jiecheng {//HDU 1042
int maxn=10005;
public static void solve(){
	Scanner cin=new Scanner(System.in);
	int n;
	while(cin.hasNext()){
		n=cin.nextInt();
		BigInteger ans=BigInteger.valueOf(1);
		for(int i=2;i<=n;i++){
			ans=ans.multiply(BigInteger.valueOf(i));
		}
		System.out.println(ans);
	}
}
	public static void main(String[] args) {
		solve();
	}
}
斐波那契數列大數版
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
    void solve () {
        Scanner cin = new Scanner(System.in);
        BigInteger f1, f2, f3, f4, ans;
        while (cin.hasNext ()) {
            int n = cin.nextInt ();
            f1 = BigInteger.valueOf (1);
            f2 = f3 = f4 = ans = f1;
            if (n <= 4) {
                System.out.println ("1");
                continue;  }
            for (int j = 5; j <= n; j++) {
                ans = f1.add (f2.add (f3.add (f4)));
                f1 = f2;
                f2 = f3;
                f3 = f4;
                f4 = ans; }
            System.out.println (ans); }
    }
    public static void main (String[] args) {
        Main work = new Main();
        work.solve (); }
}
f(n)=f(n−1)+f(n−2)+f(n−4)
import java.math.*;
import java.util.*;
public class Main {
    void solve () {
        Scanner cin = new Scanner(System.in);
        BigInteger[] ans = new BigInteger[1001];
        ans[1] = BigInteger.valueOf (1);
        ans[2] = BigInteger.valueOf (2);
        ans[3] = BigInteger.valueOf (4);
        ans[4] = BigInteger.valueOf (7);
        for (int i = 5; i <= 1000; i++) {
            ans[i] = ans[i-1].add (ans[i-2].add (ans[i-4]));
        }
        while (cin.hasNext ()) {
            int n = cin.nextInt ();
            System.out.println (ans[n]); }
    }
    public static void main (String[] args) {
        Main work = new Main();
        work.solve ();
}
高精度小數,要去掉末尾的後導0.
import java.math.*;
import java.util.*;
public class Main {
    void solve () {
        //BigInteger a, b, c;
        Scanner cin = new Scanner(System.in);
        BigDecimal a = BigDecimal.valueOf (0);
        BigDecimal b = BigDecimal.valueOf (0);
        while (cin.hasNext ()) {
            a = cin.nextBigDecimal ();
            b = cin.nextBigDecimal ();
            System.out.println
(a.add (b).stripTrailingZeros().toPlainString());
        }
    }
    public static void main (String[] args) {
        Main work = new Main();
        work.solve ();
    }
}

PKU1311八進制浮點數化爲十進制浮點數,高精度
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        BigDecimal temp, sum, ans, num; // java大數
        String str;
        int i, len;
        while (cin.hasNext()) {
            str = cin.next();
            len = str.length();
            temp = BigDecimal.valueOf(8.0);
            sum = BigDecimal.ONE;
            ans = BigDecimal.ZERO;
            for (i = 2; i < len; i++) {
           int val = str.charAt(i) - '0';
          num = BigDecimal.valueOf(val);
          sum = sum.multiply(temp); // 8的n次冪
          ans = ans.add(num.divide(sum)); // 按權累加
            }
            System.out.printf("%s [8] = ", str);
            System.out.println(ans + " [10]");
        }
    }
}

n!(1+1/2+1/3+...+1/n)
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
public class YYS {
	static  BigInteger jie(int x)
	{
		BigInteger sum= BigInteger.ONE;
	    for(int i=1;i<=x;i++)
	    {
	    	BigInteger z= BigInteger.valueOf(i);
	        sum=sum.multiply(z);
	    }
	    return sum;
	}
	public static void main(String[] args) {
	    int t=0;;
	    Scanner cin=new Scanner(System.in);
	    t=cin.nextInt();
	    for(int k=0;k<t;k++)
	    {
	        int n;
	        n=cin.nextInt();
	        BigInteger ans=BigInteger.ZERO;
	        BigInteger sum1=jie(n);
            for(int i=1;i<=n;i++){
ans=ans.add(sum1.divide(BigInteger.valueOf(i)));
            }
            System.out.println(ans+".0");
	    }
	}
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章