結果

問題 No.500 階乗電卓
ユーザー akitsu818akitsu818
提出日時 2017-04-30 22:43:18
言語 Java19
(openjdk 21)
結果
MLE  
実行時間 -
コード長 584 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 72,128 KB
実行使用メモリ 797,468 KB
最終ジャッジ日時 2023-10-12 00:00:35
合計ジャッジ時間 18,654 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 WA -
testcase_05 WA -
testcase_06 TLE -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 138 ms
55,352 KB
testcase_12 AC 143 ms
55,928 KB
testcase_13 AC 274 ms
55,536 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static boolean isbig = false;
	public static void main(String args[]){
		Scanner cin = new Scanner(System.in);
		long N = cin.nextLong();
		long tmp = 0L;
		int sub=0;
		cin.close();
		tmp = func(N);
		if(isbig){
			sub = 12-String.valueOf(tmp).length();
		}
		for(int i =0;i<sub;i++){
			System.out.print("0");
		}
		System.out.println(func(N));
	}

	static long func(long n){
		if(n==0L){
			return 1;
		}else{
			if((long)Math.pow(10, 12)>n*func(n-1)){
				isbig = true;
			}
			return (n*func(n-1))%(long)Math.pow(10, 12);
		}
	}
}
0