結果

問題 No.2181 LRM Question 2
ユーザー kotatsugamekotatsugame
提出日時 2023-01-06 22:41:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,382 bytes
コンパイル時間 1,168 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 7,460 KB
最終ジャッジ日時 2023-08-20 16:00:00
合計ジャッジ時間 3,313 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 29 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 19 ms
7,436 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 23 ms
7,460 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 15 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<atcoder/math>
using namespace std;
int F[1<<20];
pair<int,int>f(long N,int p)
{
	pair<int,int>ret=make_pair(0,1);
	while(N>=1)
	{
		long q=N/p,r=N%p;
		ret.second=(long)ret.second*atcoder::pow_mod(F[p-1],q,p)%p*F[r]%p;
		ret.first+=N=q;
	}
	return ret;
}
pair<int,int>mul(pair<int,int>ret,long v,int p)
{
	while(v%p==0)v/=p,ret.first++;
	ret.second=(long)ret.second*v%p;
	return ret;
}
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)
	{
		int p=fp.first,mod=1;
		for(int i=0;i<fp.second;i++)mod*=p;
		F[0]=1;
		for(int i=1;i<p;i++)F[i]=(long)F[i-1]*i%p;
		m.push_back(mod);
		int now=0;
		pair<int,int>x=f(2*L,p),y=f(L,p);
		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,p),2*n,p);
				y=mul(y,n,p);
			}
			int tmp=(long)x.second*atcoder::inv_mod((long)y.second*y.second%p,p)%p;
			if(x.first-y.first*2>=fp.second)tmp=0;
			else
			{
				for(int i=0;i<x.first-y.first*2;i++)tmp=(long)tmp*p%mod;
			}
			now=(now+tmp)%mod;
		}
		r.push_back(now);
	}
	long ans=atcoder::crt(r,m).first;
	ans=(ans-(R-L+1)*2%M+M)%M;
	cout<<ans<<endl;
}
0