作业帮 > 综合 > 作业

Java - 斐波那契数列 - recursive

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/10/08 13:38:37
Java - 斐波那契数列 - recursive
Write recursive Java code to compute terms of the Fibonacci sequence.Use this to compute the 5th,10th,40th,60th and 90th terms.我用基本的recursive写了一下,可是到40项以后就算不出来了.如果仅用加法算最近的两项(释放其他内存),又不算是recursive,求一种既是recursive又可以用普通的单核电脑算出来的java code...
这种recursive:
public static long fib(long n) {
if (n
Java - 斐波那契数列 - recursive
用散列表加了个缓存,可以算到long最大值存不下了吧
import java.util.Hashtable;
public class Test {
public static long fib(int n,Hashtable t) {
if (n