In each square of an $n\times{n}$ grid there is a lamp. If the lamp is touched it changes its state every lamp in the same row and every lamp in the same column (the one that are on are turned off and viceversa). At the begin, all the lamps are off. Show that  lways is possible, with an appropriated sequence of touches, that all the the lamps on the board end on and find, in function of $n$ the minimal number of touches that are necessary to turn on every lamp.
To solve this problem, we need to show that it is always possible to turn on all the lamps in an \( n \times n \) grid with an appropriate sequence of touches, and we need to find the minimal number of touches required.

1. **Initial Setup and Problem Understanding**:
   - We start with an \( n \times n \) grid where all lamps are initially off.
   - Touching a lamp toggles its state and the state of all lamps in the same row and column.

2. **Case Analysis Based on \( n \)**:
   - We will consider three cases based on the parity (odd or even) of \( n \):
     1. \( n \) is odd.
     2. \( n \) is even.

3. **Case 1: \( n \) is odd**:
   - When \( n \) is odd, we can turn on all lamps by touching each lamp in one of the rows or columns exactly once.
   - This works because each touch will toggle the state of all lamps in the same row and column, and since \( n \) is odd, each lamp will be toggled an odd number of times (once by the row touch and once by the column touch), resulting in all lamps being on.

4. **Case 2: \( n \) is even**:
   - When \( n \) is even, the situation is more complex. We need to show that touching each lamp exactly once will turn all lamps on.
   - To prove this, assume that a button is left untouched. This button will be turned on only if there are an odd number of touches along its row and column.
   - Let’s label the row as \( R \) and the column as \( C \). Each button in \( C \) needs to have an odd number of touches, so each row of the matrix obtained after excluding \( C \) and \( R \) must have an odd number of touches.
   - This matrix has dimensions \( (n-1) \times (n-1) \), so the total number of touches in this matrix must be odd.
   - Similarly, each button in \( R \) needs to have an odd number of touches, so each column of the matrix obtained after excluding \( C \) and \( R \) must have an even number of touches, so the total number of touches in this matrix must be even.
   - This leads to a contradiction, proving that no button can be left untouched.

5. **Conclusion**:
   - For odd \( n \), the minimal number of touches required is \( n \).
   - For even \( n \), the minimal number of touches required is \( n^2 \).

The final answer is \( \boxed{ n } \) for odd \( n \) and \( n^2 \) for even \( n \).