(12C) Check if given number is Fibonacci number
|
09-07-2018, 03:19 PM
Post: #4
|
|||
|
|||
RE: (12C) Check if given number is Fibonacci number
Hello, Gamo!
About overflow problem. I suggest alternative algorithm. In Binet's formula the second term tends to zero when n → ∞: ((1-√5)/2)^n → 0 So, we can approx F_n with only first term and check that estimated n is close to integer number. n ∼ (ln(√5) + ln(n)) / ln(phi), phi = (1+√5)/2 I write small Python3 script and checked that this approach is correct for all arguments > 1 up to 10^10. In program n means number to test. Function is_fib1 implements your algorithm (without overflow due to integer numbers in Python is dinamically sized). I think, it may be programmed on calculator. Code:
|
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(12C) Check if given number is Fibonacci number - Gamo - 09-04-2018, 11:58 AM
RE: (12C) Check if given number is Fibonacci number - Albert Chan - 09-04-2018, 02:00 PM
RE: (12C) Check if given number is Fibonacci number - Gamo - 09-04-2018, 02:25 PM
RE: (12C) Check if given number is Fibonacci number - stored - 09-07-2018 03:19 PM
RE: (12C) Check if given number is Fibonacci number - Albert Chan - 09-07-2018, 07:33 PM
RE: (12C) Check if given number is Fibonacci number - stored - 09-08-2018, 06:48 PM
RE: (12C) Check if given number is Fibonacci number - Albert Chan - 09-09-2018, 12:14 AM
|
User(s) browsing this thread: 1 Guest(s)