結果

問題 No.500 階乗電卓
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2017-04-07 22:57:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 654 bytes
コンパイル時間 3,525 ms
コンパイル使用メモリ 72,532 KB
実行使用メモリ 56,028 KB
最終ジャッジ日時 2023-09-07 08:32:36
合計ジャッジ時間 7,533 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,412 KB
testcase_01 AC 127 ms
55,700 KB
testcase_02 AC 125 ms
55,568 KB
testcase_03 AC 125 ms
55,940 KB
testcase_04 AC 124 ms
55,708 KB
testcase_05 AC 126 ms
55,920 KB
testcase_06 AC 125 ms
55,984 KB
testcase_07 AC 123 ms
55,944 KB
testcase_08 AC 125 ms
56,028 KB
testcase_09 AC 124 ms
55,336 KB
testcase_10 AC 125 ms
55,572 KB
testcase_11 AC 125 ms
55,608 KB
testcase_12 AC 126 ms
55,360 KB
testcase_13 AC 128 ms
55,604 KB
testcase_14 AC 123 ms
55,652 KB
testcase_15 AC 126 ms
55,864 KB
testcase_16 AC 125 ms
55,972 KB
testcase_17 AC 132 ms
55,396 KB
testcase_18 AC 126 ms
55,324 KB
testcase_19 AC 125 ms
55,768 KB
testcase_20 AC 125 ms
55,788 KB
testcase_21 AC 124 ms
55,704 KB
testcase_22 AC 125 ms
55,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        if(N>=50){
            System.out.println("000000000000");
        }else{
            long Z = 1;
            boolean boo = false;
            long mod = (long)Math.pow(10,12);
            for(int i=1; i<=N; i++){
                Z*=i;
                if(Z>=mod)boo=true;
                Z%=mod;
            }
            if(boo){
                System.out.println(String.format("%012d",Z));
            }else{
                System.out.println(Z);
            }
        }
    }
}
0