Guest User

Untitled

a guest
May 29th, 2014
248
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Tribonacci {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. BigInteger a = sc.nextBigInteger();
  8. BigInteger b = sc.nextBigInteger();
  9. BigInteger c = sc.nextBigInteger();
  10. int n = sc.nextInt();
  11. BigInteger tribNumber = BigInteger.valueOf(0);
  12.  
  13. if (n==1) {
  14. System.out.println(a);
  15. } else if (n==2) {
  16. System.out.println(b);
  17. } else if (n==3) {
  18. System.out.println(c);
  19. } else{
  20.  
  21. for (int i = 3; i < n; i++) {
  22. tribNumber = a.add(b).add(c);
  23. a = b;
  24. b = c;
  25. c = tribNumber;
  26. }
  27. System.out.println(tribNumber);
  28. }
  29. }
  30. }
RAW Paste Data