Given a number n, print the nth Lucas Number. Numbering starts from 0. Example Input 0 Output 2
Answers
Answered by
1
Answer:
Lucas Numbers
Lucas numbers are similar to Fibonacci numbers. Lucas numbers are also defined as the sum of its two immediately previous terms. But here the first two terms are 2 and 1 whereas in Fibonacci numbers the first two terms are 0 and 1 respectively.
Mathematically, Lucas Numbers may be defined as:
{\displaystyle L_{n}:={\begin{cases}2&{\text{if }}n=0;\\1&{\text{if }}n=1;\\L_{n-1}+L_{n-2}&{\text{if }}n>1.\\\end{cases}}}
The Lucas numbers are in the following integer sequence:
Write a function int lucas(int n) n as argument and returns the n’th Lucas number.
Examples :
Input : 3
Output : 4
Input : 7
Output : 29
2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123 …………..
Similar questions