关于大数的操作

来源:互联网 发布:原生js特效懒人之家 编辑:程序博客网 时间:2024/06/03 19:34

主要是运用了库函数 java.math.BigInteger
把大数转换成字符串进行运算

package 大数操作;import java.math.BigInteger;public class 大数处理BigInteger {    public static int countWays(int n) {        BigInteger[] a = new BigInteger[n + 1];        if (n == 1)            return 0;        else if (n == 2)            return 1;        else if (n == 3)            return 2;        else {            a[1] = BigInteger.ZERO;            a[2] = BigInteger.ONE;            a[3] = a[2].add(a[2]);            for (int i = 4; i <= n; i++) {                a[i] = a[i - 1].add( a[i - 2]);            }            BigInteger b = new BigInteger("1000000007");            return a[n].mod(b).intValue();        }    }    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println(Integer.MAX_VALUE+" "+countWays(99));    }}
0 0
原创粉丝点击