結果
| 問題 |
No.502 階乗を計算するだけ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-22 20:22:33 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 846 ms / 1,000 ms |
| コード長 | 1,928 bytes |
| コンパイル時間 | 9,945 ms |
| コンパイル使用メモリ | 168,032 KB |
| 実行使用メモリ | 185,696 KB |
| 最終ジャッジ日時 | 2024-06-22 20:22:55 |
| 合計ジャッジ時間 | 17,933 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 52 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (125 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 ModFactorial(long n)
{
long mod = 1000000007;
if (n == 0)
return 1;
//nがmod以上ならXは0になる
if (n >= mod)
return 0;
long[] catche_list = {
1,
67347853,
927880474, // (1 * 10^8)! % mod
261384175,
933245637, // (2 * 10^8)! % mod
112390913,
668123525, // (3 * 10^8)! % mod
386027524,
429277690, // (4 * 10^8)! % mod
462639908,
733333339, // (5 * 10^8)! % mod
696628828,
724464507, // (6 * 10^8)! % mod
92255682,
957939114, // (7 * 10^8)! % mod
217598709,
203191898, // (8 * 10^8)! % mod
823845496,
586445753, // (9 * 10^8)! % mod
315103615,
698611116, // (10 * 10^8)! % mod
};
//nを50000000で割った商がcatche_listのインデックスになり起点が求まる
long start = n / 50000000;
long ans = catche_list[start];
//起点から階乗の計算を始める
for (long i = start * 50000000 + 1; i <= n; i++)
ans = ans * i % mod;
return ans;
}
static void func()
{
long mod = 1000000007;
long a = 1;
for (long i = 1; i < mod; i++)
{
a = a * i % mod;
if (i % 50000000 == 0)
Console.WriteLine(a);
}
}
static void Main()
{
//func();
//Console.WriteLine("A");
long n;
{
long[] vs = Console.ReadLine().Split().Select(_ => long.Parse(_)).ToArray();
n = vs[0];
}
long value = ModFactorial(n);
Console.WriteLine(value);
}
}