java版本的
斐波那契数列使用通项公式Fib(n) = [(1+√5)/2]^n /√5 - [(1-√5)/2]^n /√5
package common; import java.math.BigInteger; public class TestF { public static void main (String args[]) { TestF a = new TestF(); System.out.println(a.Fibonacci(5)); } private String Fibonacci (double pNumber) { BigInteger lotteryOdds = null; long k = (long) (Math.pow(((1 + Math.sqrt(5.0)) / 2.0), pNumber) / Math.sqrt(5.0) - Math.pow(((1 - Math.sqrt(5.0)) / 2.0), pNumber) / Math.sqrt(5.0)); lotteryOdds = BigInteger.valueOf(k); return lotteryOdds.toString(); } }
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
QQ咨询|关于我们|Archiver|手机版|小黑屋|( 辽ICP备15012455号-4 ) Powered by 期权论坛 X3.2 © 2001-2016 期权工具网&期权论坛 Inc.
下载期权论坛手机APP