fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static int count = 0;
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. for (int i = 1; i <= 6; i++)
  14. call(i);
  15.  
  16. }
  17.  
  18. static void call(int n) {
  19. count = 0;
  20. System.out.println("-------------");
  21. System.out.printf("tarai(%d,%d,0)%n",2*n,n);
  22. System.out.println(tarai(2*n,n,0));
  23. System.out.println("count: " + count);
  24. }
  25.  
  26. static int tarai(int x, int y, int z) {
  27. count++;
  28. if (x <= y) {
  29. return y;
  30. } else {
  31. return tarai(tarai(x-1,y,z),tarai(y-1,z,x),tarai(z-1,x,y));
  32. }
  33. }
  34. }
Success #stdin #stdout 0.15s 34928KB
stdin
Standard input is empty
stdout
-------------
tarai(2,1,0)
2
count: 9
-------------
tarai(4,2,0)
4
count: 53
-------------
tarai(6,3,0)
6
count: 673
-------------
tarai(8,4,0)
8
count: 12605
-------------
tarai(10,5,0)
10
count: 343073
-------------
tarai(12,6,0)
12
count: 12604861