确定N是否为斐波那契,如果找不到最大的斐波那契数小于N [英] Determine whether N is fibonacci or not, if not find the largest fibonacci number smaller than N

查看:96
本文介绍了确定N是否为斐波那契,如果找不到最大的斐波那契数小于N的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定给定数字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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆