标签:www http 题解 turn val 依次 image public inf
这题要用大数,java
然后卡特兰数:有个数学模型 s[i]=c(n,2n)/(n+1)
import java.math.*; import java.util.*; public class Main {//筛法求素数 static final int maxn=120050; static boolean[]isprime=new boolean[maxn]; static int[] prime=new int[maxn]; static int pz=0; static void getPrime() { for(int i = 2; i < maxn; ++i) isprime[i]=true; for(int i = 2; i < maxn; ++i) { if(isprime[i]) prime[pz++]=i; for(int j = 0; j < pz&&(long)i*prime[j]<maxn; ++j) { isprime[i*prime[j]]=false; if(i%prime[j]==0) break; } } } static Scanner cin=new Scanner(System.in); static int n=0; public static void main(String[] args) { n=cin.nextInt(); getPrime(); BigInteger ans=B(1); for(int i = 0; i < pz&&prime[i]<=2*n; ++i) { int cnt=0,p=prime[i]; int t=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))); } static BigInteger pow(int x,int n) {//快速积 BigInteger ans=B(1),base=B(x); while(n>0) { if(n%2==1) ans=ans.multiply(base); base=base.multiply(base); n>>=1; } return ans; } static BigInteger B(int x) { return BigInteger.valueOf(x); } }
标签:www http 题解 turn val 依次 image public inf
原文地址:https://www.cnblogs.com/smallocean/p/9321120.html