Topic Link: Click to open the link
First you have to n-=2, and then there is a Cattleya number.
The previous question was H (n) = h (n-1) * (4n-2)/(n+1);
The problem is h (n) = (2n)! * n! /(n+1)!;
Then the factorial decomposition factorization:
Click to open link
The direct fast power is broken down.
#include <stdio.h> #include <iostream> #include <cmath> #include <cstring>using namespace std;# define int __int64const int N = 100000;int prime[n],primenum;//has primenum prime math.hvoid prime (int max_prime) {primenum=0; prime[primenum++]=2;for (int i=3;i<=max_prime;i+=2) for (int j=0;j<primenum;j++) if (i%prime[j]==0) Break;else if (PRIME[J]>SQRT (double) i) | | j==primenum-1) {prime[primenum++]=i;break;}} int N, m;void mul (int &x, int y) {x *= y; if (x >= m) x%= m; else if (x<0) x = x%m+m;} int Pow (int x, int y) {int ans = 1; while (y) {if (y&1) mul (ans, x); Mul (x, x); Y >>= 1; } return ans; int d[n];void work1 (int x) {for (int i = 0; prime[i]<=x; i++) {d[i] = 0; for (int j = prime[i]; j <= x; j*=prime[i]) d[i] + = x/j; }}void work2 (int x) {for (int i = 0, prime[i]<=x; i++) for (int j = prime[i]; j <= x; J*=prime[i]) D[i]-= x/j;} void Debug () {for(int i = 0; i<primenum; i++) if (D[i]) printf ("[%d,%d]\n", Prime[i],d[i]);p UTS ("");} int work () {if (m==1) return 0;if (n==1) return 1;int res = 1; F[n] = 2n!/n!/(n+1)!; Work1 (2*n); WORK2 (n); WORK2 (n+1); for (int i = 0; prime[i] <= 2*n; i++) if (D[i]) mul (res, Pow (Prime[i],d[i])); return res;} #undef Intint Main () {PRIME (1000000), while (cin>>n>>m) {n-=2;cout<< work ()%m <<endl;} return 0;}
Hnu 13101 The Triangle division of the convex Polygon Cattleya number nth%m (M can be non-prime