Let $n \in \mathbb{N}^{*}$. Find the number of $n$-digit numbers whose digits are among $\{2,3,7,9\}$ and which are divisible by 3.
Without generating function: Let $a_{0, n}, a_{1, n}, a_{2, n}$ be the number of $n$-digit numbers in $\{2,3,7,9\}$ congruent to $0,1,2$ modulo 3. We have $a_{0,0}=1, a_{1,0}=0, a_{2,0}=0$, then $a_{i, n+1}=2 a_{i, n}+a_{i+1, n}+a_{i+2, n}$, which can be solved by recurrence (but is quite tedious).

With generating function: We want the constant coefficient of $\left(X^{2}+X^{3}+X^{7}+X^{9}\right)^{n}$ modulo $1-X^{3}$. First,

$$
\left(X^{2}+X^{3}+X^{7}+X^{9}\right)^{n} \equiv\left(2+X+X^{2}\right)^{n} \quad \bmod 1-X^{3}
$$

Then, exploit the fact that $1-X^{3}=(1-X)\left(1+X+X^{2}\right)$,

$$
\left(2+X+X^{2}\right)^{n} \equiv 1^{n}=1 \quad \bmod 1+X+X^{2} \text{ and }\left(2+X+X^{2}\right)^{n} \equiv 4^{n} \bmod 1-X
$$

So, by the Chinese remainder theorem,

$$
\left(2+X+X^{2}\right)^{n} \equiv \frac{4^{n}+2}{3}+\frac{4^{n}-1}{3} X+\frac{4^{n}-1}{3} X^{2} \quad \bmod 1-X^{3}
$$

(to find this, the simplest is to set $\left(2+X+X^{2}\right)^{n} \equiv A+B X+C X^{2}$, notice that $B=C$ by symmetry, reduce modulo $1-X$ to get $A+2 B=4^{n}$, then modulo $1+X+X^{2}$ to get $A-B=1$). Thus, the answer is

$$
\frac{4^{n}+2}{3}
$$