public static long fib(long index){
long f0=0;
long f1=1;
long f2=1;
if(index==0)
return f0;
else if(index==1)
return f1;
else if(index==2)
return f2;
for(int i=3;i<=index;i++){
f0=f1;
f1=f2;
f2=f0+f1;
}
return f2;
}
来源:oschina
链接:https://my.oschina.net/u/2742034/blog/749611