結果

問題 No.2181 LRM Question 2
ユーザー kotatsugamekotatsugame
提出日時 2023-01-06 23:31:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,430 bytes
コンパイル時間 1,041 ms
コンパイル使用メモリ 84,744 KB
実行使用メモリ 7,740 KB
最終ジャッジ日時 2023-08-20 17:01:27
合計ジャッジ時間 2,546 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,460 KB
testcase_01 AC 4 ms
7,580 KB
testcase_02 AC 25 ms
7,432 KB
testcase_03 AC 3 ms
7,468 KB
testcase_04 AC 3 ms
7,624 KB
testcase_05 AC 4 ms
7,464 KB
testcase_06 AC 4 ms
7,524 KB
testcase_07 AC 4 ms
7,528 KB
testcase_08 AC 43 ms
7,580 KB
testcase_09 AC 52 ms
7,504 KB
testcase_10 AC 49 ms
7,740 KB
testcase_11 AC 50 ms
7,468 KB
testcase_12 AC 49 ms
7,516 KB
testcase_13 AC 4 ms
7,504 KB
testcase_14 AC 17 ms
7,580 KB
testcase_15 AC 4 ms
7,452 KB
testcase_16 AC 15 ms
7,436 KB
testcase_17 AC 4 ms
7,444 KB
testcase_18 AC 4 ms
7,644 KB
testcase_19 AC 4 ms
7,464 KB
testcase_20 AC 8 ms
7,520 KB
testcase_21 AC 10 ms
7,732 KB
testcase_22 AC 4 ms
7,512 KB
testcase_23 AC 3 ms
7,528 KB
testcase_24 AC 3 ms
7,728 KB
testcase_25 AC 3 ms
7,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<atcoder/math>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint;
int P;
struct val{
	long e;
	mint v;
	val(long n)
	{
		e=0;
		while(n%P==0)n/=P,e++;
		v=n;
	}
};//v*p**e
mint F[1<<20];
val f(long N)
{
	val ret(1);
	int PP=mint::mod();
	while(N>=1)
	{
		long q=N/P;
		ret.v*=F[PP-1].pow(N/PP)*F[N%PP];
		ret.e+=N=q;
	}
	return ret;
}
val mul(val a,val b)
{
	a.e+=b.e;
	a.v*=b.v;
	return a;
}
int main()
{
	long L,R;int M;
	cin>>L>>R>>M;
	vector<pair<int,int> >fac;
	{
		int m=M;
		for(int i=2;i*i<=m;i++)if(m%i==0)
		{
			fac.push_back(make_pair(i,0));
			while(m%i==0)m/=i,fac.back().second++;
		}
		if(m>1)fac.push_back(make_pair(m,1));
	}
	vector<long long>r,m;
	for(pair<int,int>fp:fac)
	{
		P=fp.first;
		int mod=1;
		for(int i=0;i<fp.second;i++)mod*=P;
		mint::set_mod(mod);
		m.push_back(mod);
		F[0]=1;
		for(int i=1;i<mod;i++)
		{
			F[i]=F[i-1];
			if(i%P!=0)F[i]*=i;
		}
		int now=0;
		val x=f(2*L),y=f(L);
		for(long n=L;n<=R;n++)
		{
			if(n>L)
			{
				//x <- 2*n-1,2*n
				//y <- n
				x=mul(mul(x,2*n-1),2*n);
				y=mul(y,n);
			}
			assert(x.e-y.e*2>=0);
			if(x.e-y.e*2>=fp.second)continue;
			int tmp=(x.v/y.v.pow(2)).val();
			for(int i=0;i<x.e-y.e*2;i++)tmp=(long)tmp*P%mod;
			now=(now+tmp)%mod;
		}
		r.push_back(now);
	}
	pair<long long,long long>ret=atcoder::crt(r,m);
	assert(ret.second==M);
	cout<<(ret.first-(R-L+1)*2%M+M)%M<<endl;
}
0