結果

問題 No.2181 LRM Question 2
ユーザー kotatsugamekotatsugame
提出日時 2023-01-06 23:04:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,481 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 85,740 KB
実行使用メモリ 7,796 KB
最終ジャッジ日時 2023-08-20 16:31:21
合計ジャッジ時間 2,500 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,460 KB
testcase_01 AC 4 ms
7,584 KB
testcase_02 AC 25 ms
7,456 KB
testcase_03 AC 3 ms
7,512 KB
testcase_04 WA -
testcase_05 AC 4 ms
7,472 KB
testcase_06 AC 4 ms
7,460 KB
testcase_07 AC 4 ms
7,520 KB
testcase_08 AC 42 ms
7,588 KB
testcase_09 WA -
testcase_10 AC 50 ms
7,468 KB
testcase_11 AC 48 ms
7,464 KB
testcase_12 AC 49 ms
7,476 KB
testcase_13 AC 3 ms
7,472 KB
testcase_14 AC 13 ms
7,648 KB
testcase_15 AC 5 ms
7,516 KB
testcase_16 AC 13 ms
7,460 KB
testcase_17 AC 4 ms
7,536 KB
testcase_18 AC 4 ms
7,528 KB
testcase_19 AC 4 ms
7,512 KB
testcase_20 AC 6 ms
7,460 KB
testcase_21 AC 10 ms
7,476 KB
testcase_22 AC 4 ms
7,516 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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