#include <iostream>
#include <algorithm>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
using namespace std;
long long int fibnacci(long long int f1,long long int f2,int n)
{
int i;
if(n==0)return 0;
else if(n==1)return f1;
else if(n==2)return f2;
else
{
for(i=1;i<=n-2;i++)
{
if(i%2)f1=f1+f2;
else f2=f1+f2;
}
if(i%2)return f2;
else return f1;
}
}
int main()
{
int N;
while(scanf("%d",&N)!=EOF)
{
printf("%lld\n",fibnacci(1,2,N));//递推也需要注意数据溢出问题
}
return 0;
}
总结
1.还是fibonacci数列