Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BigDecimal a = new BigDecimal(fibo(1000));
- BigDecimal b = new BigDecimal(fibo(10));
- System.out.println(a);
- BigDecimal x = a.divide(b, 20, RoundingMode.CEILING);
- System.out.println(x);
- }
- static long fib(int n) {
- int a = 1, b = 1, c = 0;
- for (int i = 3; i <= n; i++) {
- c = a + b;
- a = b + 1;
- b = c;
- }
- return a;
- }
- static BigInteger fibo(int n) {
- BigInteger a = BigInteger.ONE, b = BigInteger.ONE, c = BigInteger.ZERO;
- for (int i = 3; i <= n; i++) {
- c = a.add(b);
- a = b.add(BigInteger.ONE);
- b = c;
- }
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement