In an $n \times n$ square grid, $n$ squares are marked so that every rectangle composed of exactly $n$ grid squares contains at least one marked square. Determine all possible values of $n$.
To determine all possible values of \( n \) such that in an \( n \times n \) square grid, \( n \) squares are marked so that every rectangle composed of exactly \( n \) grid squares contains at least one marked square, we need to analyze the problem in detail.

1. **Case \( n = 1 \)**:
   - If \( n = 1 \), the grid is a \( 1 \times 1 \) square, and the only square is marked. This trivially satisfies the condition.

2. **Case \( n = p \) (where \( p \) is a prime number)**:
   - If \( n = p \), consider the construction where the marked squares are placed at coordinates \((i, i)\) for \( i = 1, 2, \ldots, p \). This ensures that every \( p \times 1 \) or \( 1 \times p \) rectangle contains at least one marked square. Since \( p \) is prime, there are no other divisors of \( p \) except 1 and \( p \), so this construction works.

3. **Case \( n = p^2 \) (where \( p \) is a prime number)**:
   - For \( n = p^2 \), we can use the construction \((1 + ap + b, 1 + bp + a)\) for \( 0 \le a, b < p \). This ensures that every \( p \times p \) subgrid contains at least one marked square. This construction works because it covers all possible \( p \times p \) subgrids within the \( p^2 \times p^2 \) grid.

4. **Case \( n = ab \) for \( a > b \ge 2 \)**:
   - Suppose \( n = ab \) where \( a \) and \( b \) are integers with \( a > b \ge 2 \). We need to show that this case does not work.
   - Consider covering the \( n \times n \) grid with \( b \times a \) rectangles. Suppose on the \( i \)-th row of \( a \times b \) rectangles, there are marked squares in the \( x_i \)-th columns, and on the \( j \)-th column of \( a \times b \) rectangles, there are marked squares in the \( y_j \)-th rows. Then, in the \( i \)-th rectangle from the left and the \( j \)-th rectangle from the top, there is a square at \((x_i, y_j)\) of that rectangle.
   - We claim it is possible to tile a \( b \times a \) rectangle that covers no marked squares. This can be shown by considering the intervals and the placement of marked squares. If \( b \nmid a \), there will be intervals that do not contain any marked squares, leading to a contradiction. If \( b \mid a \), the grid can be divided into identical copies of \( a \times a \) grids, and it can be shown that there will be a \( b \times \frac{a}{b} \) rectangle with no marked square.

Therefore, the only possible values of \( n \) are \( n = 1 \), \( n = p \) (where \( p \) is a prime number), and \( n = p^2 \) (where \( p \) is a prime number).

The final answer is \( \boxed{ n = 1, n = p, n = p^2 } \) where \( p \) is a prime number.