公式法
public class Main{
public static void main(String[] args) {
int s = fib(8);
System.out.println(s);
}
public static int fib(int n)
{
double phi = (1+Math.sqrt(5))/2;
return (int) Math.round(Math.pow(phi,n)/Math.sqrt(5));
}
}
这篇博客介绍了如何使用公式法计算斐波那契数列的第n项,代码采用Java编写,主要涉及数学和算法知识,通过双精度浮点数计算黄金比例并进行指数运算来得出结果。
1325

被折叠的 条评论
为什么被折叠?



