結果

問題 No.502 階乗を計算するだけ
ユーザー momen999momen999
提出日時 2017-04-17 17:05:32
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 894 bytes
コンパイル時間 2,657 ms
コンパイル使用メモリ 100,284 KB
実行使用メモリ 24,920 KB
最終ジャッジ日時 2023-09-26 10:48:19
合計ジャッジ時間 16,694 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,808 KB
testcase_01 AC 53 ms
18,532 KB
testcase_02 AC 54 ms
20,828 KB
testcase_03 AC 54 ms
20,808 KB
testcase_04 AC 55 ms
20,828 KB
testcase_05 AC 54 ms
22,904 KB
testcase_06 AC 54 ms
22,684 KB
testcase_07 AC 54 ms
18,884 KB
testcase_08 AC 54 ms
22,688 KB
testcase_09 AC 54 ms
22,788 KB
testcase_10 AC 54 ms
20,812 KB
testcase_11 AC 54 ms
22,684 KB
testcase_12 AC 54 ms
22,916 KB
testcase_13 AC 54 ms
22,684 KB
testcase_14 AC 54 ms
20,836 KB
testcase_15 AC 54 ms
18,800 KB
testcase_16 AC 54 ms
22,736 KB
testcase_17 AC 54 ms
22,704 KB
testcase_18 AC 55 ms
22,856 KB
testcase_19 AC 54 ms
20,856 KB
testcase_20 AC 55 ms
20,772 KB
testcase_21 AC 54 ms
22,836 KB
testcase_22 AC 70 ms
22,736 KB
testcase_23 AC 59 ms
20,836 KB
testcase_24 AC 64 ms
20,800 KB
testcase_25 AC 54 ms
20,624 KB
testcase_26 AC 60 ms
20,740 KB
testcase_27 AC 58 ms
22,764 KB
testcase_28 AC 59 ms
20,736 KB
testcase_29 AC 56 ms
20,756 KB
testcase_30 AC 70 ms
18,648 KB
testcase_31 AC 61 ms
20,752 KB
testcase_32 AC 647 ms
22,804 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 546 ms
20,864 KB
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 AC 80 ms
20,812 KB
testcase_41 AC 56 ms
22,792 KB
testcase_42 AC 55 ms
20,736 KB
testcase_43 AC 54 ms
18,512 KB
testcase_44 AC 55 ms
20,756 KB
testcase_45 AC 55 ms
20,688 KB
testcase_46 AC 54 ms
20,668 KB
testcase_47 AC 55 ms
20,692 KB
testcase_48 AC 55 ms
22,628 KB
testcase_49 AC 54 ms
22,828 KB
testcase_50 AC 54 ms
20,588 KB
testcase_51 AC 54 ms
20,776 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
	static long LPow (long x, long n)
	{
		if (n == 0)
			return 1;
		return x * LPow(x, n - 1);
	}

	static void Main(string[] args)
	{
		// 一億(1000000000)桁のループが重すぎるので一億の位はデータをあらかじめ算出しておく
		long[] modlist = { 1, 927880474, 933245637, 668123525, 429277690, 733333339, 724464507, 957939114, 203191898, 586445753, 698611116 };

		long n = Int64.Parse( Console.ReadLine() );

		long m = LPow(10, 9) + 7;

		if (n >= m)
		{
			Console.WriteLine(0);
			return;
		}

		long ans = modlist[n / 100000000];

		long n2 = n + 1;
		for (long i = n / 100000000 * 100000000 + 1; i < n2; ++i )
		{
			ans = i * (ans % m);
		}
		long result;
		Math.DivRem(ans, m, out result);

		Console.WriteLine(result);
	}
}
0