結果

問題 No.500 階乗電卓
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-17 20:38:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 4,789 ms
コンパイル使用メモリ 72,180 KB
実行使用メモリ 56,064 KB
最終ジャッジ日時 2023-09-07 08:46:58
合計ジャッジ時間 8,559 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,468 KB
testcase_01 AC 123 ms
56,024 KB
testcase_02 AC 123 ms
55,684 KB
testcase_03 AC 124 ms
55,576 KB
testcase_04 AC 124 ms
55,936 KB
testcase_05 AC 126 ms
55,944 KB
testcase_06 AC 127 ms
55,824 KB
testcase_07 AC 125 ms
55,628 KB
testcase_08 AC 122 ms
55,852 KB
testcase_09 AC 124 ms
55,712 KB
testcase_10 AC 123 ms
55,664 KB
testcase_11 AC 125 ms
55,712 KB
testcase_12 AC 126 ms
55,668 KB
testcase_13 AC 127 ms
55,860 KB
testcase_14 AC 129 ms
56,064 KB
testcase_15 AC 127 ms
55,736 KB
testcase_16 AC 126 ms
55,600 KB
testcase_17 AC 125 ms
55,304 KB
testcase_18 AC 128 ms
55,868 KB
testcase_19 AC 126 ms
55,700 KB
testcase_20 AC 128 ms
55,412 KB
testcase_21 AC 127 ms
55,592 KB
testcase_22 AC 125 ms
55,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class No500 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long result = 1;
		int cnt = 0;
		for(long i = 1;i <= N;i++) {
			result = result * i;
			String str = String.valueOf(result);
			if(str.length() > 12) {
				cnt++;
				str = str.substring(str.length() - 12,str.length());
			}
			result = Long.parseLong(str);
			if(result == 0) {
				break;
			}
		}
		if(cnt == 0) {
			System.out.println(result);
		}else {
		System.out.println(String.format("%012d", result));
		}
	}
}
0