/// The rule for the number of columns is as follows: 1, 1, 2, 3, 5, 8, 13, 21, 34 ...... calculate the number of digits 30th, and use recursion Algorithm .
Public static long Foo (int I) {if (I <= 0) return 0; else if (I> 0 & I <= 2) return 1; else return Foo (I-1) + Foo (I-2 );}
It is not difficult to see from the rule that the relationship between the number of digits and the number is: Starting from 3rd, each number is the sum of the first two.
If (I <= 0) return 0 // prevent the input from being 0 or a negative number, the input returns "0 ";
Else if (I> 0 & I <= 2) return 1; // If you enter 1st or 2nd bits, "1" is returned (for example, the question)
Else return Foo (I-1) + Foo (I-2); "if you enter another number, the first two values are returned. Note: Because this function is called for every value in the sequence, you need to call the first two values. This is recursion (calling itself ).
Assuming that the number of the third digit is calculated, Foo (3-1) + Foo (3-2) = Foo (2) + Foo (1) = 1 + 1 = 2;
Evaluate the value of Foo (30), return the value of Foo (29) + Foo (28), and call Foo (29) and foo (28) to evaluate their values, foo (29) must call Foo (28) and foo (27), Foo (28) must call Foo (27) and foo (26 )...... After Foo (2) and foo (1) are called, "1" is returned, and the correct answer is added.