575H - Bots - CodeForces Solution


combinatorics dp math number theory *1800

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
const int N=2e6+2;
const int M=1e6;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
int n;
int fac[N+5],inv[N+5];
int qpow(int a,int b){
	int c=1;
	while(b){
		if(b&1)c=1LL*c*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return c;
}
int C(int n,int m){
	return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	fac[0]=1;
	for(int i=1;i<=N;i++)fac[i]=1LL*i*fac[i-1]%mod;
	inv[N]=qpow(fac[N],mod-2);
	for(int i=N-1;i>=0;i--)inv[i]=1LL*(i+1)*inv[i+1]%mod;
	int ans=1;
	for(int i=2;i<=n+1;i++){
		int tmp=(mod+C(i*2,i)-C(2*i-2,i-1))%mod;
		ans=(ans+tmp)%mod;
	}
	cout<<ans;
	return 0;
}


Comments

Submit
0 Comments
More Questions

1547C - Pair Programming
550A - Two Substrings
797B - Odd sum
1093A - Dice Rolling
1360B - Honest Coach
1399C - Boats Competition
1609C - Complex Market Analysis
1657E - Star MST
1143B - Nirvana
1285A - Mezo Playing Zoma
919B - Perfect Number
894A - QAQ
1551A - Polycarp and Coins
313A - Ilya and Bank Account
1469A - Regular Bracket Sequence
919C - Seat Arrangements
1634A - Reverse and Concatenate
1619C - Wrong Addition
1437A - Marketing Scheme
1473B - String LCM
1374A - Required Remainder
1265E - Beautiful Mirrors
1296A - Array with Odd Sum
1385A - Three Pairwise Maximums
911A - Nearest Minimums
102B - Sum of Digits
707A - Brain's Photos
1331B - Limericks
305B - Continued Fractions
1165B - Polycarp Training