結果
| 問題 |
No.2181 LRM Question 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-01-06 22:41:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,382 bytes |
| コンパイル時間 | 802 ms |
| コンパイル使用メモリ | 83,252 KB |
| 実行使用メモリ | 6,996 KB |
| 最終ジャッジ日時 | 2024-11-30 19:07:53 |
| 合計ジャッジ時間 | 2,375 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 5 RE * 4 |
ソースコード
#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;
}