結果
問題 |
No.502 階乗を計算するだけ
|
ユーザー |
|
提出日時 | 2024-06-22 19:58:18 |
言語 | C# (.NET 8.0.404) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,229 bytes |
コンパイル時間 | 15,849 ms |
コンパイル使用メモリ | 165,632 KB |
実行使用メモリ | 191,084 KB |
最終ジャッジ日時 | 2024-06-22 19:59:02 |
合計ジャッジ時間 | 41,758 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | RE * 46 TLE * 6 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (94 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System; using System.Collections.Generic; using System.Linq; public class Program { static long ModPow(long a, long b, long m) { long ans = 1; while (0 < b) { if ((b & 1) == 1) { ans = (ans * a) % m; } a = (a * a) % m; b >>= 1; } return ans; } static void func() { long mod = 1000000007; long a = 1; for (long i = 1; i < mod; i++) { a = a * i % mod; if (i % 100000000 == 0) { //a = (a * a) % mod; Console.WriteLine(a); } } //cout<<"}"<<endl; } static long ModFactorial(long n) { long mod = 1000000007; if (n == 0) return 0; //nがmod以上ならXは0になる if (n >= mod) return 0; long[] catche_list = { 1, 927880474, // (1 * 10^8)! % mod 933245637, // (2 * 10^8)! % mod 668123525, // (3 * 10^8)! % mod 429277690, // (4 * 10^8)! % mod 733333339, // (5 * 10^8)! % mod 724464507, // (6 * 10^8)! % mod 957939114, // (7 * 10^8)! % mod 203191898, // (8 * 10^8)! % mod 586445753, // (9 * 10^8)! % mod 698611116, // (10 * 10^8)! % mod }; //nを10^8で割った商がcatche_listのインデックスになり起点が求まる long start = n / 100000000; long ans = catche_list[start]; //起点から階乗の計算を始める for (long i = start * 100000000 + 1; i <= n; i++) ans = ans * i % mod; return ans; } static void Main() { long n; { long[] vs = Console.ReadLine().Split().Select(_ => long.Parse(_)).ToArray(); n = vs[0]; } long value = ModFactorial(n); Console.WriteLine(value); long A, B, M; { long[] vs = Console.ReadLine().Split().Select(_ => long.Parse(_)).ToArray(); A = vs[0]; B = vs[1]; M = vs[2]; } } }