結果
問題 | No.502 階乗を計算するだけ |
ユーザー |
|
提出日時 | 2017-04-17 17:05:32 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 894 bytes |
コンパイル時間 | 1,868 ms |
コンパイル使用メモリ | 104,448 KB |
実行使用メモリ | 17,792 KB |
最終ジャッジ日時 | 2024-07-19 05:30:52 |
合計ジャッジ時間 | 12,373 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 48 TLE * 4 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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); } }