以后大数用java的BigInteger类好了
代码
/*
* create by zzy at 2017,2:03:40 PM
*/
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
static int max=105;
static BigInteger[]h=new BigInteger[max];
public static void getCatlanten(){
h[0]=BigInteger.valueOf(1);
h[1]=BigInteger.valueOf(1);
for(int i=2;i<max;i++){
//hn=(4*n-2)/(n+1) *h[n-1]
h[i]=h[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1));
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int n;
getCatlanten();
while(in.hasNextInt()){
n=in.nextInt();
System.out.println(h[n]);
}
}
}

本文介绍了一种利用Java的BigInteger类解决大数运算问题的方法。通过实例代码展示了如何初始化BigInteger数组并进行特定数学运算,如乘法和除法,以此来计算Catalan数列。适用于需要处理超过常规整型变量所能表示范围的大数运算场景。
1940

被折叠的 条评论
为什么被折叠?



