java 10000的阶乘

2021-06-21 11:06

阅读:468

标签:stat   阶乘   --   main   system.in   big   can   car   exti   

package test;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class MyTest {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        List result = new ArrayList();
        int carry = 0;
        int digit = 1;
        int temp = 1;
        int i,j;
        result.add(1);
        for(i = 2;i){
            for(j = 0,carry = 0;j){
                temp = result.get(j)*i+carry;
                result.set(j, temp%10000);
                carry  = temp/10000;
            }
            
            while(carry != 0){
                result.add(digit++, carry%10000);
                carry/=10000;
            }
        }
        int count = 1;
        System.out.print(result.get(digit-1));
        for(i = digit-1;i>=1;i--){
            count++;
            if(result.get(i-1)){
                System.out.print("000");
            }else if(result.get(i-1)){
                System.out.print("00");
            }else if(result.get(i-1)){
                System.out.print("0");
            }
            System.out.print(result.get(i-1));
            
        }
    }
}        

 

java 10000的阶乘

标签:stat   阶乘   --   main   system.in   big   can   car   exti   

原文地址:https://www.cnblogs.com/mophy/p/9684085.html


评论


亲,登录后才可以留言!