結果

問題 No.500 階乗電卓
ユーザー tentententen
提出日時 2022-08-02 10:12:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,392 bytes
コンパイル時間 3,009 ms
コンパイル使用メモリ 74,244 KB
実行使用メモリ 55,888 KB
最終ジャッジ日時 2023-09-30 09:01:08
合計ジャッジ時間 5,895 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,808 KB
testcase_01 AC 45 ms
49,612 KB
testcase_02 AC 45 ms
49,396 KB
testcase_03 AC 45 ms
49,396 KB
testcase_04 AC 45 ms
49,524 KB
testcase_05 AC 45 ms
49,372 KB
testcase_06 AC 118 ms
55,556 KB
testcase_07 AC 45 ms
49,448 KB
testcase_08 AC 44 ms
49,416 KB
testcase_09 AC 45 ms
49,508 KB
testcase_10 AC 45 ms
49,372 KB
testcase_11 AC 118 ms
55,888 KB
testcase_12 AC 118 ms
55,568 KB
testcase_13 AC 118 ms
53,844 KB
testcase_14 AC 117 ms
55,344 KB
testcase_15 AC 117 ms
55,096 KB
testcase_16 AC 118 ms
55,520 KB
testcase_17 AC 118 ms
55,672 KB
testcase_18 AC 45 ms
47,504 KB
testcase_19 AC 44 ms
49,440 KB
testcase_20 AC 45 ms
49,492 KB
testcase_21 AC 46 ms
49,576 KB
testcase_22 AC 45 ms
49,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static final long MOD = 1000000000000L;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextLong();
        if (n / 5 >= 12) {
            System.out.println("000000000000");
        } else {
            long ans = 1;
            boolean over = false;
            for (int i = 1; i <= n; i++) {
                ans *= i;
                over |= (ans >= MOD);
                ans %= MOD;
            }
            if (over) {
                System.out.printf("%012d\n", ans);
            } else {
                System.out.println(ans);
            }
        }
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0