UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213823#2157. 数列erican100646ms16788kbC++111.6kb2024-11-13 20:36:192024-11-13 23:06:49

answer

// Problem: B. 数列
// Contest: undefined - NOIP2024训练赛 04
// URL: http://noi.ac/contest/1156/problem/2157
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// Challenger: Erica N
// ----
// 
#include<bits/stdc++.h>

using namespace std;
#define rd read()
#define ull unsigned long long
#define int long long 
#define pb push_back
#define itn int
#define ps second 
#define pf first


#define rd read()
int read(){
  int xx = 0, ff = 1;char ch = getchar();
  while (ch < '0' || ch > '9'){
    if (ch == '-')ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
  return xx * ff;
}
#define zerol = 1
#ifdef zerol
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() {cerr << endl;}
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
	for (auto v: a) cerr << v << ' ';err(x...);
}
template<typename T, typename... A>
void err(T a, A... x) {
	cerr << a << ' ';err(x...);
}
#else
#define dbg(...)
#endif
const int N=2e6+5;
const ull P=137;
int MOD;
const int INF=1e18+7;
/*

策略


*/	

int ksm(int a,int b){
	int res=1;
	while(b){
		if(b&1)res=res*a%MOD;
		b>>=1;
		a=a*a%MOD;
	}
	return res;
}

int fac[N],inv[N];

void init(){
	fac[0]=1;
	for(int i=1;i<N;i++){
		fac[i]=fac[i-1]*i%MOD;
	}
	
}


inline int C(int n,int m){
	if(m>n)return 0;
	return fac[n]*ksm(fac[n-m],MOD-2)%MOD*ksm(fac[m],MOD-2)%MOD;
}

signed main(){
	int n=rd;
	MOD=rd;
	init();
	
	cout<<C(2*n,n)*ksm(n+1,MOD-2)%MOD;
	// cdbg(C(2*n,n),inv[n+1])
}


详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 27ms
memory: 16784kb

input:

921 998054347

output:

345389219

result:

ok single line: '345389219'

Test #2:

score: 5
Accepted
time: 35ms
memory: 16788kb

input:

926 998064329

output:

458756691

result:

ok single line: '458756691'

Test #3:

score: 5
Accepted
time: 35ms
memory: 16784kb

input:

1000 998074327

output:

457273797

result:

ok single line: '457273797'

Test #4:

score: 5
Accepted
time: 26ms
memory: 16788kb

input:

952 998084303

output:

329700115

result:

ok single line: '329700115'

Test #5:

score: 5
Accepted
time: 40ms
memory: 16784kb

input:

989 998094347

output:

94788253

result:

ok single line: '94788253'

Test #6:

score: 5
Accepted
time: 31ms
memory: 16784kb

input:

902 998104313

output:

911969455

result:

ok single line: '911969455'

Test #7:

score: 5
Accepted
time: 31ms
memory: 16788kb

input:

914 998114333

output:

827812986

result:

ok single line: '827812986'

Test #8:

score: 5
Accepted
time: 30ms
memory: 16784kb

input:

986 998124313

output:

169699253

result:

ok single line: '169699253'

Test #9:

score: 5
Accepted
time: 38ms
memory: 16788kb

input:

947 998134339

output:

761932751

result:

ok single line: '761932751'

Test #10:

score: 5
Accepted
time: 38ms
memory: 16784kb

input:

934 998144339

output:

42889072

result:

ok single line: '42889072'

Test #11:

score: 5
Accepted
time: 38ms
memory: 16788kb

input:

991572 998154343

output:

277089318

result:

ok single line: '277089318'

Test #12:

score: 5
Accepted
time: 34ms
memory: 16788kb

input:

932800 998164337

output:

945072504

result:

ok single line: '945072504'

Test #13:

score: 5
Accepted
time: 34ms
memory: 16788kb

input:

903603 998174341

output:

29916736

result:

ok single line: '29916736'

Test #14:

score: 5
Accepted
time: 33ms
memory: 16784kb

input:

958646 998184331

output:

802903490

result:

ok single line: '802903490'

Test #15:

score: 5
Accepted
time: 21ms
memory: 16784kb

input:

983016 998194349

output:

802900579

result:

ok single line: '802900579'

Test #16:

score: 5
Accepted
time: 27ms
memory: 16788kb

input:

922347 998204353

output:

228575331

result:

ok single line: '228575331'

Test #17:

score: 5
Accepted
time: 32ms
memory: 16784kb

input:

976053 998214317

output:

982618317

result:

ok single line: '982618317'

Test #18:

score: 5
Accepted
time: 32ms
memory: 16784kb

input:

957300 998224351

output:

514549818

result:

ok single line: '514549818'

Test #19:

score: 5
Accepted
time: 27ms
memory: 16788kb

input:

921760 998234353

output:

470386410

result:

ok single line: '470386410'

Test #20:

score: 5
Accepted
time: 37ms
memory: 16788kb

input:

912948 998244353

output:

129235345

result:

ok single line: '129235345'