10000以内的N!

 1 import java.io.*;
 2 import java.lang.*;
 3 import java.text.*;
 4 import java.util.*;
 5 import java.math.*;
 6 class Main
 7 {
 8     public static void main(String[] argc)
 9     {
10         Scanner cin=new Scanner(System.in);
11         BigInteger a1,n,i;
12         while(cin.hasNextBigInteger())
13         {
14             a1=cin.nextBigInteger();
15             n=BigInteger.valueOf(1);
16             for(i=BigInteger.valueOf(1);i.compareTo(a1)<=0;i=i.add(BigInteger.valueOf(1)))
17             {
18                 n=n.multiply(i);
19             }
20             System.out.println(n);
21         }
22     }
23 }

 

 1 import java.util.*;
 2 import java.math.*;
 3 class Main
 4 {
 5     public static void main(String args[])
 6     {
 7         Scanner cin=new Scanner(System.in);
 8         BigInteger a;
 9         int n,i;
10         while(cin.hasNext())
11         {
12             n=cin.nextInt();
13             a=BigInteger.valueOf(1);
14             for(i=1;i<=n;i++)
15             {
16                 a=a.multiply(BigInteger.valueOf(i));
17             }
18             System.out.println(a);
19         }
20     }
21 }

 

posted @ 2012-08-22 12:25  疼痛落在指尖  阅读(179)  评论(0编辑  收藏  举报