Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么用JAVA高精都过不了???不是说至少精确十二位就行了么~~~

Posted by lanseniao at 2010-08-15 16:07:32 on Problem 1671 and last updated at 2010-08-15 16:32:00
import java.math.*;
import java.io.*;
import java.util.*;

public class Main 
{
    public static void main(String[] args) throws IOException
    {
        Scanner cin=new Scanner(System.in);
        
        int i,j,n;
    	BigInteger num[][]=new BigInteger[105][105],ans;

    	for(i=0;i<=100;i++)
    		for(j=0;j<=100;j++)
    			num[i][j]=BigInteger.ZERO;
    	
    	num[1][1]=BigInteger.ONE;
    	for(i=2;i<=100;i++)
    		for(j=1;j<=i;j++)
    		{
    			num[i][j]=BigInteger.valueOf(j).multiply(num[i-1][j]);
    			num[i][j]=num[i][j].add(num[i-1][j-1]);
    		}

        while(cin.hasNext())
        {
        	ans=BigInteger.ZERO;
        	n=cin.nextInt();
        	
        	if(n==0)
        		break;
        	
        	for(i=1;i<=n;i++)
        		ans=ans.add(num[n][i]);
        	
        	System.out.println(ans);
        }
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator