隨筆 - 147  文章 - 71  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(1)

          隨筆分類(146)

          隨筆檔案(147)

          文章分類(28)

          文章檔案(28)

          喜歡的Blog

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          http://www.spoj.pl/problems/FCTRL2/
          要點:
          1、BigInteger屬于java.math.BigInteger,因此在每次使用前都要import 這個類。
          2、其常用的構造方法有:
          BigInteger(String val)
                    將 BigInteger 的十進制字符串表示形式轉換為 BigInteger。
          BigInteger(String val, int radix)
                    將指定基數的 BigInteger 的字符串表示形式轉換為 BigInteger。
          如要將int型的2轉換為BigInteger型,要寫為BigInteger two=new BigInteger("2"); //注意2雙引號不能省略
          3、BigInteger類模擬了所有的int型數學操作,如add()==“+”,divide()==“-”等,但注意其內容進行數學運算時不能直接使用數學運算符進行運算,必須使用其內部方法。而且其操作數也必須為BigInteger型。
          如:two.add(2)就是一種錯誤的操作,因為2沒有變為BigInteger型。
          4、當要把計算結果輸出時應該使用.toString方法將其轉換為10進制的字符串,詳細說明如下:
          String toString()
                    返回此 BigInteger 的十進制字符串表示形式。
          輸出方法:System.out.print(two.toString());
          5、三個經常用到的函數:
          BigInteger remainder(BigInteger val)
                    返回其值為 (this % val) 的 BigInteger。
          BigInteger negate()
                    返回其值是 (-this) 的 BigInteger。
          int compareTo(BigInteger val)
                    將此 BigInteger 與指定的 BigInteger 進行比較。
          remainder用來求余數。
          negate將操作數變為相反數。
          compare的詳解如下:

          compareTo

          public int compareTo(BigInteger val)

          將此 BigInteger 與指定的 BigInteger 進行比較。對于針對六個布爾比較運算符 (<, ==, >, >=, !=, <=) 中的每一個運算符的各個方法,優先提供此方法。執行這些比較的建議語句是:(x.compareTo(y) <op> 0),其中 <op> 是六個比較運算符之一。

          指定者:接口 Comparable<BigInteger> 中的 compareTo
          參數:
          val - 將此 BigInteger 與之比較的 BigInteger。
          返回: 當此 BigInteger 在數值上小于、等于或大于 val 時,返回 -1,0,或 1

          import java.util.*;
          import java.io.*;
          import java.math.*;

          public class SPOJ_24{
              
              
          public static void main(String rgs[]) throws Exception
              
          {
                  BufferedReader stdin 
          = 
                      
          new BufferedReader(
                          
          new InputStreamReader(System.in));        
                  String line 
          = stdin.readLine();  
                  
          int i,j,k,n = Integer.parseInt(line);
                  
          for(i=0;i<n;i++){
                      line 
          = stdin.readLine();
                      k 
          = Integer.parseInt(line);
                      BigInteger a 
          = BigInteger.valueOf(1);
                      BigInteger c 
          = BigInteger.valueOf(1);
                      
          for(j=2;j<=k;j++){
                          BigInteger b 
          = BigInteger.valueOf(j);
                          c 
          = a.multiply(b);
                          a 
          = c;
                      }

                      System.out.println(c);
                  }

              }

          }
          posted on 2009-08-21 10:39 飛翔天使 閱讀(178) 評論(0)  編輯  收藏 所屬分類: spoj
          主站蜘蛛池模板: 台南县| 钦州市| 庆云县| 新安县| 金湖县| 奎屯市| 桦南县| 蕲春县| 伊吾县| 定安县| 班玛县| 佛坪县| 高雄市| 宜兰市| 山丹县| 色达县| 石棉县| 睢宁县| 博客| 东城区| 东海县| 五原县| 宽甸| 慈利县| 杭州市| 通辽市| 六枝特区| 潮安县| 二连浩特市| 包头市| 榆中县| 太湖县| 内江市| 北票市| 绵阳市| 鲁甸县| 通江县| 日土县| 洛阳市| 同江市| 平乡县|