This question already has an answer here:
- Trump needs your help to stop the Starman! 22 answers
Write a program or function that takes an input greater than or equal to 2. It should output a truthy or falsy value corresponding to whether the input is a Lucas number or not. You may take input from STDIN, or whichever source is most suitable to you.
This question is different to this one because this question is specifically for Lucas numbers only, and not Fibonacci numbers at all, whereas that question was Lucas number, Fibonacci numbers and both possible combinations of them. This question was, however, inspired by that question and is similar in some regards.
Lucas numbers are the numbers that result from the rules following: the first Lucas number is a 2, the second is a 1, and each term after that is the sum of the previous two. Yes, it is very similar to the Fibonacci sequence, but this has the added advantage of converging closer to the golden ratio, phi, faster than Fibonacci numbers do.
Input Output -------------- 3 True 4 True 7 True 8 False 10 False 3421 False 9349 True
- Your program/function must run in a reasonable amount of time. It should terminate within seconds and minutes, not hours and days.
- Your program must not calculate all the Lucas numbers up to the input number
This is code golf, so the shortest code in bytes wins.