Let $S$ be a subset of \( \{1, 2, \ldots, 500\} \) such that no two distinct elements of $S$ have a product that is a perfect square. Find, with proof, the maximum possible number of elements in $S$.

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