結果

問題 No.500 階乗電卓
ユーザー 37zigen37zigen
提出日時 2017-04-07 22:38:53
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 857 bytes
コンパイル時間 2,650 ms
コンパイル使用メモリ 74,800 KB
実行使用メモリ 57,728 KB
最終ジャッジ日時 2023-09-23 01:23:20
合計ジャッジ時間 5,766 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 119 ms
55,864 KB
testcase_05 AC 118 ms
56,084 KB
testcase_06 AC 119 ms
55,804 KB
testcase_07 AC 114 ms
56,180 KB
testcase_08 AC 118 ms
55,832 KB
testcase_09 AC 118 ms
56,176 KB
testcase_10 AC 114 ms
55,660 KB
testcase_11 AC 119 ms
55,892 KB
testcase_12 AC 117 ms
56,004 KB
testcase_13 AC 115 ms
55,800 KB
testcase_14 AC 117 ms
55,708 KB
testcase_15 AC 119 ms
56,092 KB
testcase_16 AC 116 ms
55,760 KB
testcase_17 AC 118 ms
55,748 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		if (N > 120) {
			System.out.println(000000000000);
			return;
		}
		long ans = 1;
		boolean f = false;
		for (long i = 1; i <= N; ++i) {
			if (ans * i >= (long) 1e12)
				f = true;
			ans = (ans * i) % ((long) 1e12);
		}
		if (f) {
			int[] arr = new int[12];
			for (int i = 0; i < 12; ++i) {
				arr[i] = (int) (ans % 10);
				ans /= 10;
				if (ans == 0)
					break;
			}
			for (int i = arr.length - 1; i >= 0; --i) {
				System.out.print(arr[i]);
			}
			System.out.println();
			return;
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0