Depending on what one wants to do with this, one can treat the process as an isoseries, based on $a(n+1) = k \cdot a(n) - a(n-1)$. There are algorithms that can generate these numbers for any form of multiplication, including the modular form (ie $(a\cdot b ) mod c$.
The following iterations show the value for finding $a(37)$. The first two columns are actual integers as shown. 37 is odd, which produces a '1'. This means that we keep the values in O0 and O1. The value of 37 divided by 2 gives 18, an even number. We keep the valuse in E0 and E1.
The values in brackets are the values of $a(n)$, shown as (n). The third column is powers of 2, by $a(2n) = a(n)^2 - 2$. The values in columns 4 onwards show the powers, in steps of the powers. We have, eg $a(5) = $a(2) \cdot a(3) - a(1)$.
$a(0)=2 = x^0 + x^{-0}$, and $a(1) = a$.
P2 E0 O0 E1 O1
37 1 (1) (0) (1) (2) (3)
18 0 (2) (1) (3) (5)
9 1 (4) (1) (5) (9) (13)
4 0 (8) (5) (13) (21)
2 0 (16) (5) (21) (37)
1 1 (32) (5) (37)