結果

問題 No.500 階乗電卓
ユーザー Grenache
提出日時 2017-04-09 11:09:02
言語 Java
(openjdk 23)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 3,891 ms
コンパイル使用メモリ 74,676 KB
実行使用メモリ 41,532 KB
最終ジャッジ日時 2024-06-25 02:58:31
合計ジャッジ時間 7,794 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder500 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		long n = sc.nextLong();

		if (n > 100) {
			pr.println("000000000000");
		} else {
			long ret = 1;
			boolean flag = false;
			for (int i = 2; i <= n; i++) {
				ret *= i;
				if (ret >= 1_000_000_000_000L) {
					ret %= 1_000_000_000_000L;
					flag = true;
				}
			}

			if (flag) {
				pr.printf("%012d\n", ret);
			} else {
				pr.println(ret);
			}
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0