随笔 - 147  文章 - 71  trackbacks - 0
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(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 飞翔天使 阅读(167) 评论(0)  编辑  收藏 所属分类: spoj

只有注册用户登录后才能发表评论。


网站导航: