結果

問題 No.2176 LRM Question 1
ユーザー Kome_soudou
提出日時 2023-01-06 22:13:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 512 bytes
コンパイル時間 1,610 ms
コンパイル使用メモリ 168,252 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-11-30 18:22:28
合計ジャッジ時間 2,825 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int64_t l, r, m;
	cin >> l >> r >> m;
	
	vector<int64_t> fact(m);
	fact[0] = 1;
	for(int64_t i = 1; i < m; i++) fact[i] = (fact[i - 1] * i) % m;
	
	int64_t ans = 0;
	int64_t rui = 1;
	if(m <= l)
	{
		cout << 0 << endl;
		return 0;
	}
	for(int64_t i = 1; i < l; i++)
	{
		rui *= fact[i];
		rui %= m;
	}
	for(int64_t i = l; i <= r; i++)
	{
		if(m <= i) break;
		rui *= fact[i];
		rui %= m;
		ans += rui;
		ans %= m;
	}
	cout << ans << endl;
	return 0;
}
0