結果

問題 No.500 階乗電卓
ユーザー 101000010101000010
提出日時 2017-05-17 03:23:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 3,219 ms
コンパイル使用メモリ 71,744 KB
実行使用メモリ 56,304 KB
最終ジャッジ日時 2023-09-07 08:41:31
合計ジャッジ時間 6,103 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
55,580 KB
testcase_01 AC 103 ms
55,988 KB
testcase_02 AC 103 ms
56,040 KB
testcase_03 AC 103 ms
55,824 KB
testcase_04 AC 109 ms
56,036 KB
testcase_05 AC 105 ms
55,576 KB
testcase_06 AC 104 ms
55,912 KB
testcase_07 AC 105 ms
55,764 KB
testcase_08 AC 106 ms
55,696 KB
testcase_09 AC 103 ms
55,732 KB
testcase_10 AC 105 ms
55,844 KB
testcase_11 AC 104 ms
55,720 KB
testcase_12 AC 107 ms
55,900 KB
testcase_13 AC 109 ms
56,212 KB
testcase_14 AC 114 ms
56,304 KB
testcase_15 AC 121 ms
55,704 KB
testcase_16 AC 120 ms
55,980 KB
testcase_17 AC 122 ms
56,052 KB
testcase_18 AC 106 ms
55,620 KB
testcase_19 AC 105 ms
55,968 KB
testcase_20 AC 113 ms
55,864 KB
testcase_21 AC 107 ms
55,564 KB
testcase_22 AC 104 ms
55,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No500 {
    public static void main(String[] args){
        long N=0;
        Scanner sc = new Scanner(System.in);
        N = sc.nextLong();
        
        culc(N);
    }
    static void culc(long N){
        long mod = (long) Math.pow(10, 12); //1,000,000,000,000
        boolean moreThan12Digits = false;
        long ans=1;
        
        for(int i=2; i<=N; i++){    
            ans *= i;
            if(moreThan12Digits && ans == 0)break;  //下12桁が全て0になったら終了
            if(ans >= mod){
                ans %= mod;
                moreThan12Digits = true;
            }
        }
        if(moreThan12Digits){
            System.out.printf("%012d\n", ans);
        }else{
            System.out.println(ans);
        }
    }
}
0