Lucas numbers

The Lucas numbers L₀, L₁, L₂, … are closely related to the Fibonacci
numbers. For any non-negative integer n ≥ 0, the nth Lucas number is
defined as
$$L_n = \left\{
\begin{array}{ll}
2 & \mathrm{if} \;\; n=0,\\
1 & \mathrm{if} \;\; n=1,\\
L_{n-1}+L_{n-2} & \mathrm{if} \;\; n>1.
\end{array}
\right.$$

Input

The input starts with an integer C, the number of cases. On each of the
following C lines is a single integer n which satisfies 0 ≤ n ≤ 30.

Output

For each case n, output the Lucas number L_(n) on a single line.

Problem information

Author: Anders Jonsson

Generation: 2026-01-25T14:27:34.817Z

© Jutge.org, 2006–2026.
https://jutge.org
