问题描述
如何确定给定数字N
是否是斐波那契数字,如果该数字不是斐波那契数字,我如何*确定小于N
的最大斐波那契数字?
我通过生成限制为N
的斐波那契数列找到了解决方案.
在Python中还有更好的方法吗?
人们考虑在投票失败时,我接受了此处提供的解决方案.我认为这不值得,因为我已经发布了我需要的东西并从你们那里得到了解决方案.
谢谢.
关于某些整数N
是否为斐波那契数的简单测试如下:
N is a Fibonacci number iff either (5 * n^2 + 4) or (5 * n^2 - 4) is a square number.
请参见此处以获取巧妙的证明(第417页): http ://www.fq.math.ca/Scanned/10-4/advanced10-4.pdf
如果事实证明N
不是斐波那契数字,那么最简单的方法就是继续尝试使用较小的数字,直到找到一个为止,尽管对于较大的N
可能会花费很长时间. >
How can I determine whether a given number N
is a fibonacci number or not, if that number is not a fibonacci number how can I*determine the largest fibonacci number smaller than N
?
I found the solution via generating the series of fibonacci number with limit N
.
Is there any better way to do this in Python?
guys consider while DOWN VOTES, I've accepted the solution provided here. I do not think it as worthwhile since I have posted what I need and got the solution from you guys.
Thank You.
A simple test for whether some integer N
is a Fibonacci number is as follows:
N is a Fibonacci number iff either (5 * n^2 + 4) or (5 * n^2 - 4) is a square number.
See here for the ingenious proof (page 417): http://www.fq.math.ca/Scanned/10-4/advanced10-4.pdf
If it turns out that N
is not a Fibonacci number, then the simplest method is just to keep trying with smaller numbers until you find one, although this could take a very long time for large N
.
这篇关于确定N是否为斐波那契,如果找不到最大的斐波那契数小于N的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!