結果
問題 | No.2176 LRM Question 1 |
ユーザー |
|
提出日時 | 2023-07-21 21:02:33 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 763 bytes |
コンパイル時間 | 5,813 ms |
コンパイル使用メモリ | 172,800 KB |
実行使用メモリ | 10,368 KB |
最終ジャッジ日時 | 2024-09-21 22:19:31 |
合計ジャッジ時間 | 6,948 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 4 |
ソースコード
import std; void main () { long L, R; int M; readln.read(L, R, M); solve(L, R, M); } void solve (long L, long R, int M) { if (M < L) { writeln(0); return; } long[] factorial = new long[](M+1); factorial[0] = 1 % M; foreach (i; 1..M+1) { factorial[i] = i*factorial[i-1] % M; } long ans = 0; long product = 1; foreach (i; 1..L+1) { product *= factorial[i]; product %= M; } for (long i = L+1; i <= min(M, R); i++) { ans += product; ans %= M; product *= factorial[i]; product %= M; } writeln(ans); } void read(T...)(string S, ref T args) { auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }