Java - 斐波那契数列 - recursive

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
小蓝企鹅 1年前 已收到1个回答 举报

磊磊520 花朵

共回答了23个问题采纳率:100% 举报

用散列表加了个缓存,可以算到long最大值存不下了吧
import java.util.Hashtable;
public class Test {
public static long fib(int n,Hashtable t) {
if (n

1年前

10
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.100 s. - webmaster@yulucn.com