結果

問題 No.2181 LRM Question 2
ユーザー 沙耶花沙耶花
提出日時 2023-01-06 22:39:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,671 bytes
コンパイル時間 6,259 ms
コンパイル使用メモリ 264,008 KB
実行使用メモリ 61,872 KB
最終ジャッジ日時 2023-08-20 15:56:39
合計ジャッジ時間 12,503 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 682 ms
61,872 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 26 ms
14,752 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 794 ms
61,760 KB
testcase_09 AC 282 ms
61,520 KB
testcase_10 AC 985 ms
61,652 KB
testcase_11 AC 988 ms
61,688 KB
testcase_12 AC 901 ms
14,820 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 88 ms
55,944 KB
testcase_15 AC 28 ms
17,624 KB
testcase_16 AC 96 ms
43,660 KB
testcase_17 AC 102 ms
39,484 KB
testcase_18 AC 63 ms
31,196 KB
testcase_19 AC 53 ms
31,540 KB
testcase_20 AC 101 ms
55,584 KB
testcase_21 AC 169 ms
49,000 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,380 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;
	if(M==1){
		cout<<0<<endl;
		return 0;
	}
	
	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);
	vector<vector<int>> n(M,vector<int>(ps.size(),0));
	for(int i=1;i<M;i++){
		int c = i;
		rep(j,ps.size()){
			while(c%ps[j]==0){
				n[i][j]++;
				c/=ps[j];
			}
		}
		v[i] = c;
		v[i] *= v[i-1];
		rep(j,ps.size()){
			n[i][j] += n[i-1][j];
		}
	}
	/*
	rep(i,M){
		rep(j,ps.size()){
			cout<<n[i][j]<<',';
		}
		cout<<endl;
	}
	*/
	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;
			long long 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;
	}
	rep(i,n){
		ans /= i+1;
		ans /= i+1;
	}
	cout<<ans<<endl;
	*/
	
    return 0;
}
0