hdu1261 java大整数乘除.求阶层

 1 import java.io.*;
 2 import java.util.*;
 3 import java.math.BigInteger;
 4 
 5 public class Main {
 6     public static void main(String[] args)
 7     {
 8         Scanner in=new Scanner(System.in);
 9         int[] s=new int[30];
10         while (in.hasNext())
11         {
12             int n=in.nextInt(),sum=0;
13             if (n==0) break;
14             BigInteger ans=new BigInteger("1");
15             for (int i=1;i<=n;i++)
16             {
17                 s[i]=in.nextInt();
18                 sum+=s[i];
19             }
20             for (int i=1;i<=sum;i++)
21                 ans=ans.multiply(BigInteger.valueOf(i));
22             for (int i=1;i<=n;i++)
23                 for (int j=1;j<=s[i];j++)
24                     ans=ans.divide(BigInteger.valueOf(j));
25             System.out.println(ans);
26         }
27     }
28 }

整数数组定义:int[] s=new int[30];

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1261

posted on 2014-12-30 22:05  xiao_xin  阅读(140)  评论(0编辑  收藏  举报

导航