fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10. long x1, x2, x3, x4 = 0;
  11. long n = in.nextLong();
  12. x1 = 2;
  13. x2 = 4;
  14. x3 = 7;
  15. for (int i = 3; i < n; i++) {
  16. x4 = x1 + x2 + x3;
  17. x1 = x2;
  18. x2 = x3;
  19. x3 = x4;
  20. }
  21. if (n == 1)
  22. System.out.println(2);
  23. else if (n == 2)
  24. System.out.println(4);
  25. else if (n == 3)
  26. System.out.println(7);
  27. else
  28. System.out.println(x4);
  29. }
  30. }
Success #stdin #stdout 0.06s 2184192KB
stdin
4
stdout
13