Advertisement
Guest User

Untitled

a guest
May 25th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class FastFib {
  5.  
  6. public static void main(String[] args) {
  7. Scanner gwS = new Scanner(System.in);
  8. System.out.println(ah3(new BigInteger[][]{{BigInteger.ONE, BigInteger.ONE}, {BigInteger.ONE, BigInteger.ZERO}}, gwS.nextInt() - 1)[0][0]);
  9. }
  10.  
  11. private static BigInteger[][]bsg(BigInteger[][] dpl, BigInteger[][] zuy) {
  12. return new BigInteger[][]{{dpl[0][0].multiply(zuy[0][0]).add(dpl[0][1].multiply(zuy[1][0])), dpl[0][0].multiply(zuy[0][1]).add(dpl[0][1].multiply(zuy[1][1]))}, {dpl[1][0].multiply(zuy[0][0]).add(dpl[1][1].multiply(zuy[1][0])), dpl[1][0].multiply(zuy[0][1]).add(dpl[1][1].multiply(zuy[1][1]))},};
  13. }
  14.  
  15. private static BigInteger[][]ah3(BigInteger[][] nkG, int hx3) {
  16. if (hx3 == 0) {return new BigInteger[][]{{BigInteger.ONE, BigInteger.ZERO}, {BigInteger.ZERO, BigInteger.ONE}}; } else if (hx3 % 2 == 0) { return ah3(bsg(nkG, nkG), hx3 / 2); } else { return bsg(ah3(nkG, hx3 - 1), nkG); }
  17. }
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement