public class arithmetic {
//递归方式
public static long f(int n){
long a = 0;
if(n == 1 || n ==2){
a = 1;
}else if(n > 2){
a = f(n-1)+f(n-2);
}
return a;
}
//非递归
public static long f2(int n){
if(n==1||n==2){
return 1;
}
long[] a = new long[n+1];
a[0] = 0;
a[1] = 1;
a[2] = 1;
for(int i=3;i <= n; i++){
a[i] = a[i-1]+a[i-2];
}
return a[n];
}
//求和
public static long sumFunc(int n){
if(n<1){
return 0;
}
long sum = 0;
for(int i = 1; i<=n; i++){
sum += f(i);
//sum += f(i); 递归模式
}
return sum;
}
public static void main(String[] args) {
long sum = 0;
int i = 20;
sum = sumFunc(i);
System.out.println(sum);
}
}