These things have been studied, and the appropriate search terms for Googling are _sparse rulers_ , _complete rulers_ , _optimal rulers_ , and _perfect rulers_ , but as far as I know there is no known simple solution which works for all lengths $n$.
The wikipedia article on Sparse Rulers gives many examples and a number of references where you can find out what has already done on this problem.