結果

問題 No.500 階乗電卓
ユーザー uafr_csuafr_cs
提出日時 2017-04-07 22:37:09
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 957 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 76,516 KB
実行使用メモリ 54,344 KB
最終ジャッジ日時 2024-07-16 01:11:53
合計ジャッジ時間 5,537 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 122 ms
54,140 KB
testcase_05 AC 122 ms
54,212 KB
testcase_06 AC 118 ms
54,060 KB
testcase_07 AC 119 ms
54,124 KB
testcase_08 AC 119 ms
54,200 KB
testcase_09 AC 113 ms
54,232 KB
testcase_10 AC 120 ms
54,336 KB
testcase_11 AC 131 ms
54,204 KB
testcase_12 AC 124 ms
54,176 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 123 ms
54,344 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

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) ? "0" : mod.toString());
	}
}
0