Let $a_1,$ $a_2,$ $\dots$ be a sequence of real numbers such that for all positive integers $n,$
\[\sum_{k = 1}^n a_k \left( \frac{k}{n} \right)^2 = 1.\]Find the smallest $n$ such that $a_n < \frac{1}{2018}.$

Let's think step by step and output the final answer within \boxed{}.
user