結果

問題 No.500 階乗電卓
ユーザー uafr_cs
提出日時 2017-04-07 22:36:46
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 968 bytes
コンパイル時間 1,911 ms
コンパイル使用メモリ 76,748 KB
実行使用メモリ 54,480 KB
最終ジャッジ日時 2024-07-16 01:05:32
合計ジャッジ時間 5,494 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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