結果

問題 No.2176 LRM Question 1
ユーザー daiotadaiota
提出日時 2023-01-07 05:34:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 564 bytes
コンパイル時間 1,904 ms
コンパイル使用メモリ 165,264 KB
実行使用メモリ 11,224 KB
最終ジャッジ日時 2023-08-20 22:10:54
合計ジャッジ時間 3,497 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 53 ms
11,180 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 37 ms
11,224 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 37 ms
11,128 KB
testcase_09 AC 37 ms
10,908 KB
testcase_10 AC 45 ms
9,892 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 37 ms
11,104 KB
testcase_14 AC 54 ms
11,216 KB
testcase_15 AC 42 ms
9,476 KB
testcase_16 AC 34 ms
9,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 34 ms
10,312 KB
testcase_19 AC 24 ms
9,436 KB
testcase_20 AC 10 ms
4,896 KB
testcase_21 AC 22 ms
7,620 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 20 ms
7,324 KB
testcase_24 AC 17 ms
7,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
typedef long long ll;
typedef pair<int,int> P;

ll p[1000010];

int main(void){
	ll i;

	cin.tie(0);  ios_base::sync_with_stdio(false);

	ll L,R,M;
	cin >> L >> R >> M;

	ll a=1;
	for(i=1;i<=M-1;i++){
		a*=i;
		a%=M;
		p[i]=a;
	}
	for(i=2;i<=M-1;i++){
		p[i]*=p[i-1];
		p[i]%=M;
	}

	ll ans=0;
	if(L<M && M<=R){
		for(i=L;i<=M-1;i++){
			ans+=p[i];
			ans%=M;
		}
	}
	else if(R<M){
		for(i=L;i<=R;i++){
			ans+=p[i];
			ans%=M;
		}
	}

	cout << ans << endl;


	return 0;
}
0