Is is possible to obtain exactly 16 black cells? We are given an $18*18$ table, all of whose cells may be black or white. Initially all the cells are colored white. We may perform the following operation:
Choose one column or one row and change the colour of all cells in this column or row. Is it possible by repeating the operation to obtain a table with exactly $16$ black cells?
I know that this question is based on invariant principle but I am not getting the invariant.
 A: First notice that the order in which we perform the row/column operations doesn't matter and that using two times the same column/row does nothing. Now suppose we can make $16$ black cells using $r$ row-moves and $c$ column-moves. Imagine to color the columns and rows we used, every coloured cell is now black, except the cells coloured 'two times' that are white. The total number of coloured cells is
$$18(r+c)-rc.$$
The number of cells coloured two times are $rc$. So the total number of black cells are
$$18(r+c)-2rc.$$
Now we have to solve (for $0\le r,c\le18$)
$$18(r+c)-2rc=16$$
that can be rewritten as
$$r=9-\frac{73}{9-c}.$$
Since $r$ must be a integer, we have that $(9-c) \mid 73$, the only possibility is $c=8$, but we would have $r<0$. Hence there are no solutions.
EDIT: As pointed out by @filipos we must consider also the case $c=10$, which gives $r>18$ and so it has to be discarded.
A: Well, mrprottolo gave a similar answer, but not identical, and I already typed this out, so I'll hit "Post" anyway!

First of all, note that these operations commute with each other! Second, by shuffling the rows and columns as necessary, we can assume that only the first $m$ rows and the first $n$ columns are flipped.
So how many black cells are there? Measure the two rectangles:
$$n(18-m)+m(18-n)=18m+18n-2mn$$
Setting that equal to $16$, we get:
$$9m+9n-mn=8$$
Conclude that both $m$ and $n$ are even, and neither is a multiple of $3$. So $m\geq 2$, and by symmetry, we can assume $m\leq 9$, which forces $m\leq 8$. But
$$n=\frac{9m-8}{m-9}$$
is negative on that range, a contradiction.
