Compute the nth Lucas number and display the Lucas sequence up to that term.
Lucas numbers follow the same recurrence as Fibonacci (L(n) = L(n−1) + L(n−2)) but start with L(0) = 2 and L(1) = 1 instead of 0 and 1. The sequence begins 2, 1, 3, 4, 7, 11, 18, 29, … Like Fibonacci numbers, the ratio of consecutive Lucas numbers converges to the golden ratio φ. Lucas numbers satisfy the identity L(n) = F(n−1) + F(n+1).
Lucas recurrence
L(n) = L(n−1) + L(n−2), L(0) = 2, L(1) = 1
Relation to Fibonacci
L(n) = F(n−1) + F(n+1)
They share the same recurrence rule (each term is the sum of the two preceding terms) but differ in initial conditions: Fibonacci starts 0, 1 while Lucas starts 2, 1.
They appear in primality testing (Lucas-Lehmer test for Mersenne primes), combinatorial identities, and the theory of continued fractions. They also satisfy many identities that mirror those of Fibonacci numbers.