結果

問題 No.2181 LRM Question 2
ユーザー kotatsugamekotatsugame
提出日時 2023-01-06 22:59:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,449 bytes
コンパイル時間 1,214 ms
コンパイル使用メモリ 85,660 KB
実行使用メモリ 7,812 KB
最終ジャッジ日時 2023-08-20 16:25:54
合計ジャッジ時間 3,082 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,552 KB
testcase_01 AC 4 ms
7,480 KB
testcase_02 AC 41 ms
7,684 KB
testcase_03 AC 4 ms
7,540 KB
testcase_04 WA -
testcase_05 AC 4 ms
7,476 KB
testcase_06 AC 4 ms
7,476 KB
testcase_07 AC 4 ms
7,472 KB
testcase_08 AC 88 ms
7,476 KB
testcase_09 WA -
testcase_10 AC 97 ms
7,496 KB
testcase_11 AC 93 ms
7,564 KB
testcase_12 AC 93 ms
7,480 KB
testcase_13 AC 4 ms
7,492 KB
testcase_14 AC 15 ms
7,488 KB
testcase_15 AC 4 ms
7,468 KB
testcase_16 AC 20 ms
7,468 KB
testcase_17 AC 5 ms
7,652 KB
testcase_18 AC 5 ms
7,488 KB
testcase_19 AC 5 ms
7,556 KB
testcase_20 AC 7 ms
7,552 KB
testcase_21 AC 20 ms
7,488 KB
testcase_22 AC 5 ms
7,484 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);
			}
			int tmp=(x.second/y.second.pow(2)).val();
			assert(x.first-y.first*2>=0);
			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);
	}
	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