Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: keyvank2
- TASK: combo
- LANG: C++
- */
- #include <bits/stdc++.h>
- #define ff first
- #define ss second
- #define pb push_back
- #define mp make_pair
- #define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
- #define FORV(i, v) FOR(i, 0, ((v).size()))
- #define REP(i,j,k) for(int i = j; i >= (int)(k); i--)
- #define setmax(i) const int maxn = (int) i;
- #define setmod(i) const int MOD = (int) i;
- #define all(a) a.begin(),a.end()
- #define autodef(x,v) typeof(v) x = (v)
- #define autoref(x,v) typeof(v)& x = (v)
- #define forit(it, c) for (autodef(it, ((c).begin())); it != ((c).end()); ++it)
- //typedef complex<double> Point;
- //#define X real()
- //#define Y imag()
- using namespace std;
- //ifstream fin("");
- //ofstream fout("");
- //#define cin fin
- //#define cout fout
- typedef long long ll;
- typedef long double ld;
- typedef vector<int> vi;
- typedef pair<int,int> pii;
- typedef pair<ll,ll> pll;
- typedef pair<ld,ld> pdd;
- typedef pair<pii,int> ppi;
- typedef pair<pll,ll> ppl;
- typedef pair<int,pii> pip;
- typedef pair<ll,pll> plp;
- typedef pair<pii,pii> ppp;
- const int INF = (int) 2e9;
- const ll INFL = (ll) 9e18;
- const int MAXINT = ((~0) ^ (1 << 31));
- const ll MAXLL = ((~0) ^ ((ll)1 << 63));
- template<class T> inline T pow2(T a) { return a*a;}
- template<class T> inline bool mineq(T& a, T b){return (a > b) ? (a=b, true) : false;}
- template<class T> inline bool maxeq(T& a, T b){return (a < b) ? (a=b, true) : false;}
- //srand (time(NULL));
- bool debug = 1;
- setmod(1e9+7);
- setmax(2e5+10);
- ll fact[maxn], rfact[maxn];
- ll powmod(ll a, ll b)
- {
- if(!b)
- return 1;
- ll t = powmod(a,b/2);
- t = (t*t)%MOD;
- if(b&1)
- t = (t*a)%MOD;
- return t;
- }
- void pre()
- {
- fact[0] = 1;
- FOR(i,1,maxn)
- fact[i] = (fact[i-1]*i)%MOD;
- FOR(i,0,maxn)
- rfact[i] = powmod(fact[i],MOD-2);
- if(debug)
- {
- FOR(i,0,20)
- cout << fact[i] << " ";
- cout << endl;
- FOR(i,0,20)
- cout << rfact[i] << " ";
- cout << endl;
- }
- }
- ll catalan(ll n)
- {
- return (fact[2*n]*rfact[n])%MOD *rfact[n] %MOD *powmod(n+1,MOD-2)%MOD;
- }
- ll catalan2(ll n)
- {
- if(n == 0)
- return 1;
- ll ans = 0;
- FOR(i,0,n)
- ans += catalan2(i)*catalan2(n-1-i);
- return ans;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);cin.tie(0);
- pre();
- int t;
- cin >> t;
- FOR(i,0,t)
- {
- int n;
- cin >> n;
- cout << catalan(n) << endl;
- if(debug)
- {
- cout << "validator : " << catalan2(n) << endl;
- assert(catalan(n) == catalan2(n));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement