Last active
February 20, 2019 10:00
-
-
Save lapla-cogito/6f96e9e2395e4c2273d4f8a9f287c395 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
//nから1までの階乗を求める | |
long long upperfloor(long long n) { | |
long long ans = 1; | |
while (n) { | |
ans *= n; | |
--n; | |
} | |
return ans; | |
} | |
//aからbまでの階乗を求める | |
long long specialupper(long long a, long long b) { | |
long long ans = 1; | |
while (a >= b) { | |
ans *= a; | |
--a; | |
} | |
return ans; | |
} | |
//カタラン数の一般項を計算する | |
long long catalan(long long n) { | |
return specialupper(2 * n, n + 2) / upperfloor(n); | |
} | |
int main() { | |
int N; | |
cin >> N; | |
cout << catalan(N) << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment