結果

問題 No.500 階乗電卓
ユーザー uafr_csuafr_cs
提出日時 2017-04-07 22:36:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 968 bytes
コンパイル時間 3,767 ms
コンパイル使用メモリ 86,880 KB
実行使用メモリ 57,984 KB
最終ジャッジ日時 2023-09-23 00:35:35
合計ジャッジ時間 7,074 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,500 KB
testcase_01 AC 125 ms
55,520 KB
testcase_02 AC 124 ms
55,928 KB
testcase_03 AC 123 ms
55,816 KB
testcase_04 AC 126 ms
55,548 KB
testcase_05 AC 124 ms
55,740 KB
testcase_06 AC 123 ms
55,472 KB
testcase_07 AC 123 ms
56,120 KB
testcase_08 AC 124 ms
56,316 KB
testcase_09 AC 116 ms
57,984 KB
testcase_10 AC 121 ms
56,408 KB
testcase_11 AC 122 ms
55,872 KB
testcase_12 AC 121 ms
55,760 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 127 ms
56,204 KB
testcase_16 AC 126 ms
56,008 KB
testcase_17 AC 127 ms
55,996 KB
testcase_18 AC 127 ms
55,704 KB
testcase_19 AC 123 ms
56,052 KB
testcase_20 AC 122 ms
55,984 KB
testcase_21 AC 123 ms
55,656 KB
testcase_22 AC 124 ms
55,756 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));
			//System.out.println(next_value);
			
			final BigInteger value_mod = value.mod(BigInteger.valueOf(MOD));
			final BigInteger next_mod  = next_value.mod(BigInteger.valueOf(MOD));
			
			if(value_mod.equals(next_mod)){
				break;
			}else{
				value = next_value;
			}
		}
		
		final BigInteger mod = value.mod(BigInteger.valueOf(MOD));
		System.out.println(mod.equals(BigInteger.ZERO) ? "000000000000" : mod.toString());
	}
}
0