通项公式 an=1/sqrt(5)*[((1+sqrt(5))/2)^n-((1-sqrt(5))/2)^n]
(其实百度百科一下就知道了)
excel公式=1/power(5,1/2)*(((1+power(5,1/2))/2)^A1-((1-power(5,1/2))/2)^A1)
其中A1填N
public static void main(String[] args) {
for (int i = 1; i <= 20; i++) {
int count = getCount(i);
System.out.println(count);
}
}
public static int getCount(int x) {
if (x == 1 || x == 2) {
return 1;
} else {
return getCount(x - 1) + getCount(x - 2);
}
}
/**输出结果
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
*/