Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * author: Mathura Tudu
- * created: 25.04.2020 20:52:53 IST
- **/
- #include <bits/stdc++.h>
- using namespace std;
- using ull = unsigned long long int;
- ull binomial(int n, int k) {
- ull res = 1;
- if (k > n - k) {
- k = n - k;
- }
- for (int i = 0; i < k; i++) {
- res *= (n - i);
- res /= (i + 1);
- }
- return res;
- }
- ull catalan(int n) {
- ull c = binomial(2*n, n);
- // return 2nCn / (n + 1)
- return c / (n + 1);
- }
- int main() {
- //catalan[n - 2] gives the answer for n-sided polygon
- for (int n = 3; n <= 10; n++) {
- cout << catalan(n - 2) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement