Java - 斐波那契数列 - recursiveWrite recursive Java code to compute terms of the Fibonacci sequence.Use this to compute the 5th,10th,40th,60th and 90th terms.我用基本的recursive写了一下,可是到40项以后就算不出来了.如果仅
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/18 09:42:33
Java - 斐波那契数列 - recursiveWrite recursive Java code to compute terms of the Fibonacci sequence.Use this to compute the 5th,10th,40th,60th and 90th terms.我用基本的recursive写了一下,可是到40项以后就算不出来了.如果仅
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 - 斐波那契数列 - recursiveWrite recursive Java code to compute terms of the Fibonacci sequence.Use this to compute the 5th,10th,40th,60th and 90th terms.我用基本的recursive写了一下,可是到40项以后就算不出来了.如果仅
用散列表加了个缓存,可以算到long最大值存不下了吧
import java.util.Hashtable;
public class Test {
public static long fib(int n,Hashtable t) {
if (n