Problem

Source: Iranian TST 2019, second exam day 2, problem 6

Tags: number theory



For any positive integer $n$, define the subset $S_n$ of natural numbers as follow $$ S_n = \left\{x^2+ny^2 : x,y \in \mathbb{Z} \right\}.$$Find all positive integers $n$ such that there exists an element of $S_n$ which doesn't belong to any of the sets $S_1, S_2,\dots,S_{n-1}$. Proposed by Yahya Motevassel