java 大数

题目 http://acm.nyist.net/JudgeOnline/status.php?do=search&pid=&userid=wsp&language=0&result=0

 
import java.math.BigInteger;

import java.util.Scanner;

public class Main{

/**
* @param args
*/
public static void main(String[] args) {
Scanner ss=new Scanner(System.in);
int n=ss.nextInt();
while(n-->0)
{
BigInteger ans=new BigInteger("4");
int m;
m=ss.nextInt();
//System.out.println(m);
for(int i=1;i<m;++i)
ans=ans.multiply(BigInteger.valueOf(4));
//ans.multiply(BigInteger.valueOf(4));
//System.out.println(ans);
System.out.println(ans.subtract(BigInteger.valueOf(1)).divide(BigInteger.valueOf(3)));
}
}

}
http://acm.nyist.net/JudgeOnline/problem.php?pid=28

import java.math.BigInteger;
import java.util.Scanner;

public class Main{

/**
* @param args
*/
public static void main(String[] args) {
Scanner ss=new Scanner(System.in);
int n=ss.nextInt();
BigInteger ans=BigInteger.ONE;
for(int i=1;i<=n;i++)
{
ans=ans.multiply(BigInteger.valueOf(i));
}
System.out.println(ans);
}

}
http://acm.nyist.net/JudgeOnline/problem.php?pid=114

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

public class Main
{
	public static void main(String args[])
	{
		Scanner cin = new Scanner(System.in);	
		BigInteger a[] = new BigInteger[100];
		while(cin.hasNext())
		{
			for(int i = 0; i <= 2; ++i)
				a[i] = cin.nextBigInteger();
			for(int i = 3; i <= 99; ++i)
				a[i] = a[i - 1].add(a[i - 2]).add(a[i - 3]);
			System.out.println(a[99]);
		}
	}
}
 
 
高精度幂

题目:http://acm.nyist.net/JudgeOnline/problem.php?pid=155

import java.math.BigDecimal;
import java.util.Scanner;

public class Main{

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
          Scanner ss=new Scanner(System.in);
          while(ss.hasNext())
          {
        	  BigDecimal s1=ss.nextBigDecimal();
        	  BigDecimal s2=s1;
        	  int n=ss.nextInt();
        	  String res = s1.pow(n).stripTrailingZeros().toPlainString(); //整数去掉小数点和后面的0 topla为避免科学计数法  
              if(res.startsWith("0")) //去掉前导0  
              {  
                  res = res.substring(1);  //从第二个数开始返回一个新的字符串
              }  
              System.out.println(res);  
          }
	}

}

你可能感兴趣的:(java 大数)