The title describes a train of n carriages, sequentially numbered,..., N. Each compartment has two ways of movement, into the stack and out of the stack, asked how many of the possible arrangement of the N-section car stack.
Enter a number, n (n<=60000)
The output of a number s indicates the possible arrangement of the stack of n carriages:
This is going to take a large number, Java
Then Cattleya number: There is a mathematical model s[i]=c (N,2N)/(n+1)
Combinatorial number formula: This is always unable to remember the problem can not be directly asked, will tle. It is necessary to find out how many times each factorization of the result is power, and then use the fast power, and then multiply all the results of exponentiation. Http://www.cnblogs.com/sciorz/p/9263122.html
Importjava.math.*;ImportJava.util.*; Public classMain {//The sieve method to calculate prime number Static Final intmaxn=120050; Static Boolean[]isprime=New Boolean[MAXN]; Static int[] Prime=New int[MAXN]; Static intPz=0; Static voidGetprime () { for(inti = 2; i < MAXN; ++i) isprime[i]=true; for(inti = 2; i < MAXN; ++i) {if(Isprime[i]) prime[pz++]=i; for(intj = 0; J < pz&& (Long) i*prime[j]<maxn; ++j) {Isprime[i*prime[j]]=false; if(i%prime[j]==0) Break; } } } StaticScanner cin=NewScanner (system.in); Static intN=0; Public Static voidMain (string[] args) {n=Cin.nextint (); Getprime (); BigInteger ans=b (1); for(inti = 0; I < pz&&prime[i]<=2*n; ++i) {intcnt=0,p=Prime[i]; intT=n*2; while(t>0) {//(2n! )cnt+=t/p; T/=p; } t=N; while(t>0) {//(n! *n! )Cnt-=t/p*2; T/=p; } ans=ans.multiply (POW (p,cnt)); } System.out.println (Ans.divide (B (n+1))); } StaticBigInteger Pow (intXintN) {//Fast ProductBigInteger ans=b (1), base=B (x); while(n>0) { if(n%2==1) ans=ans.multiply (base); Base=base.multiply (base); N>>=1; } returnans; } StaticBigInteger B (intx) {returnbiginteger.valueof (x); }}
View Code
Train Access Stacks Java