Problem

Source: Olimphíada 2022- Problem 4/Level 2

Tags: algebra, Sequence



Let $a_1,a_2,\dots$ be a sequence of integers satisfying $a_1=2$ and: $$a_n=\begin{cases}a_{n-1}+1, & \text{ if }n\ne a_k \text{ for some }k=1,2,\dots,n-1; \\ a_{n-1}+2, & \text{ if } n=a_k \text{ for some }k=1,2,\dots,n-1. \end{cases}$$Find the value of $a_{2022!}$.