結果

問題 No.500 階乗電卓
ユーザー uafr_csuafr_cs
提出日時 2017-04-07 22:57:43
言語 Java19
(openjdk 21)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 2,325 ms
コンパイル使用メモリ 73,784 KB
実行使用メモリ 56,440 KB
最終ジャッジ日時 2023-09-07 08:33:06
合計ジャッジ時間 5,905 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
56,116 KB
testcase_01 AC 107 ms
55,700 KB
testcase_02 AC 109 ms
56,052 KB
testcase_03 AC 111 ms
55,704 KB
testcase_04 AC 110 ms
55,776 KB
testcase_05 AC 109 ms
55,680 KB
testcase_06 AC 118 ms
55,660 KB
testcase_07 AC 112 ms
56,268 KB
testcase_08 AC 113 ms
55,460 KB
testcase_09 AC 111 ms
56,144 KB
testcase_10 AC 109 ms
55,732 KB
testcase_11 AC 113 ms
56,140 KB
testcase_12 AC 117 ms
55,956 KB
testcase_13 AC 109 ms
55,544 KB
testcase_14 AC 112 ms
55,872 KB
testcase_15 AC 109 ms
55,544 KB
testcase_16 AC 109 ms
56,020 KB
testcase_17 AC 111 ms
56,440 KB
testcase_18 AC 109 ms
55,812 KB
testcase_19 AC 130 ms
55,768 KB
testcase_20 AC 128 ms
56,036 KB
testcase_21 AC 128 ms
55,632 KB
testcase_22 AC 126 ms
55,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static final long MOD = 1000000000000l;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final long N = sc.nextLong();
		
		BigInteger value = BigInteger.ONE;
		for(long i = 2; i <= Math.min(N, 120); i++){
			final BigInteger next_value = value.multiply(BigInteger.valueOf(i));
			value = next_value;
		}
		
		final int length = value.toString().length();
		if(length <= 12){
			System.out.println(value);
		}else{
			final BigInteger mod = value.mod(BigInteger.valueOf(MOD));
			
			System.out.println(mod.equals(BigInteger.ZERO) ? "000000000000" : String.format("%012d", mod.longValue()));
		}
	}
}
0