Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1.         BigDecimal a = new BigDecimal(fibo(1000));
  2.         BigDecimal b = new BigDecimal(fibo(10));
  3.         System.out.println(a);
  4.         BigDecimal x = a.divide(b, 20, RoundingMode.CEILING);
  5.         System.out.println(x);
  6.     }
  7.  
  8.     static long fib(int n) {
  9.         int a = 1, b = 1, c = 0;
  10.         for (int i = 3; i <= n; i++) {
  11.             c = a + b;
  12.             a = b + 1;
  13.             b = c;
  14.         }
  15.         return a;
  16.     }
  17.  
  18.     static BigInteger fibo(int n) {
  19.         BigInteger a = BigInteger.ONE, b = BigInteger.ONE, c = BigInteger.ZERO;
  20.         for (int i = 3; i <= n; i++) {
  21.             c = a.add(b);
  22.             a = b.add(BigInteger.ONE);
  23.             b = c;
  24.         }
  25.         return a;
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement