結果

問題 No.2181 LRM Question 2
ユーザー 沙耶花沙耶花
提出日時 2023-01-06 23:00:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,440 bytes
コンパイル時間 4,174 ms
コンパイル使用メモリ 263,264 KB
実行使用メモリ 7,172 KB
最終ジャッジ日時 2023-08-20 16:27:07
合計ジャッジ時間 9,931 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 610 ms
6,940 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 10 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 728 ms
6,940 KB
testcase_09 AC 205 ms
7,172 KB
testcase_10 AC 923 ms
7,052 KB
testcase_11 AC 930 ms
6,944 KB
testcase_12 AC 902 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 20 ms
6,796 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 43 ms
5,688 KB
testcase_17 AC 54 ms
5,476 KB
testcase_18 AC 26 ms
4,896 KB
testcase_19 AC 16 ms
5,080 KB
testcase_20 AC 32 ms
6,848 KB
testcase_21 AC 105 ms
6,336 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 2000000000000000005

int main(){
	
	long long L,R,M;
	cin>>L>>R>>M;
	
	mint::set_mod(M);
	
	vector<int> ps;
	{
		int m = M;
		for(int i=2;i<=M;i++){
			if(m%i==0){
				ps.push_back(i);
				while(m%i==0){
					m /= i;
				}
			}
		}
	}
	
	vector<mint> v(M,1);
	for(int i=1;i<M;i++){
		int c = i;
		rep(j,ps.size()){
			while(c%ps[j]==0){
				c/=ps[j];
			}
		}
		v[i] = c;
		v[i] *= v[i-1];
	}
	
	mint ans = 0;
	
	for(long long i=L;i<=R;i++){
		long long x = i*2;
		long long y = i;
		mint cv = 1;
		cv *= v.back().pow(x/M);
		cv *= v[x%M];
		rep(j,2){
			cv /= v.back().pow(y/M);
			cv /= v[y%M];
		}
		rep(j,ps.size()){
			long long t = x;
			__int128 s = 0;
			while(t!=0){
				s += t/ps[j];
				t /= ps[j];
			}
			rep(k,2){
				t = y;
				while(t!=0){
					s -= t/ps[j];
					t /= ps[j];
				}
			}
			cv *= mint(ps[j]).pow(s);
		}
		
		ans += cv - 2;
	}
	
	cout<<ans.val()<<endl;
	
	/*
	long long n;
	cin>>n;
	
	long long ans = 0;
	
	for(long long i=1;i<=n-1;i++){
		long long x = 1;
		for(long long j=1;j<=i;j++){
			x *= (n-j+1) * (n-j+1);
		}
		for(long long k=i+1;k<=n;k++){
			x *= k * k;
		}
		ans += x;
	}
	//cout<<ans<<endl;
	rep(i,n){
		ans /= i+1;
		ans /= i+1;
	}
	cout<<ans<<endl;
	*/
	
    return 0;
}
0