fork(2) 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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int num = 8;
  13. long[] ans = new long[num];
  14.  
  15. for (int i = 0; i < num; i++)
  16. ans[i] = 0;
  17.  
  18. ans[0] = ans[1] = 1;
  19.  
  20. for (int i = 2; i < num; i++) {
  21. System.out.println("R(" + i + ") = >");
  22. for (int j = 0; j < i / 2; j++) {
  23. ans[i] += ans[j];
  24. System.out.println("\t{" + j + "} + R(" + (j) + ") = " + ans[j] + "");
  25. }
  26. int j = i / 2;
  27. if (i % 2 == 0) {
  28. ans[i] += ans[j] - 1;
  29. System.out.println("\t{" + j + "} + R(" + (j) + ") - 1 = " + (ans[j] - 1) + "");
  30. }
  31. else {
  32. ans[i] += ans[j];
  33. System.out.println("\t{" + j + "} + R(" + (j) + ") = " + ans[j] + "");
  34. }
  35.  
  36. System.out.println("\t = > " + ans[i]);
  37. }
  38.  
  39. System.out.println(Arrays.toString(ans));
  40. }
  41. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
R(2) = >
	{0} + R(0) = 1
	{1} + R(1) - 1 = 0
	 = > 1
R(3) = >
	{0} + R(0) = 1
	{1} + R(1) = 1
	 = > 2
R(4) = >
	{0} + R(0) = 1
	{1} + R(1) = 1
	{2} + R(2) - 1 = 0
	 = > 2
R(5) = >
	{0} + R(0) = 1
	{1} + R(1) = 1
	{2} + R(2) = 1
	 = > 3
R(6) = >
	{0} + R(0) = 1
	{1} + R(1) = 1
	{2} + R(2) = 1
	{3} + R(3) - 1 = 1
	 = > 4
R(7) = >
	{0} + R(0) = 1
	{1} + R(1) = 1
	{2} + R(2) = 1
	{3} + R(3) = 2
	 = > 5
[1, 1, 1, 2, 2, 3, 4, 5]