Problem

Source: 2023 Thailand Online MO P9

Tags: number theory, Integer sequence, algebra



Find all sequences of positive integers $a_1,a_2,\dots$ such that $$(n^2+1)a_n = n(a_{n^2}+1)$$for all positive integers $n$.