zornitza_gencheva

Tribonachi

May 26th, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. import sun.rmi.runtime.NewThreadAction;
  5.  
  6. public class tribonachi
  7. {
  8. public static void main(String[] args)
  9. {
  10. Scanner scan = new Scanner(System.in);
  11. BigInteger first = scan.nextBigInteger();
  12.  
  13. scan.nextLine();
  14. BigInteger second = scan.nextBigInteger();
  15.  
  16. scan.nextLine();
  17. BigInteger third = scan.nextBigInteger();
  18.  
  19. scan.nextLine();
  20. int n = scan.nextInt();
  21. BigInteger tN = new BigInteger("0");
  22.  
  23. for (int i = 0; i < n - 3; i++)
  24. {
  25. tN = first.add(second);
  26. tN = tN.add(third);
  27. BigInteger temp = tN;
  28. first = second;
  29. second = third;
  30. third = temp;
  31. }
  32.  
  33. System.out.println(tN);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment