1020 handshakes

1020 handshakes

The participants of a mathematical olympiad are occupying all the seats of a rectangular hall in which the seats are aligned in rows and columns.

At the beginning of the test, a teacher suggests that they wish each other luck by shaking hands so that each of the contestants shakes hands with those who are next to him (front, back, sides and diagonally) and only these.

Someone notes that 1020 handshakes were given. How many participants are there, if it is known that the number of rows is a multiple of 7?


Possible cases:

The minimum case that meets all the conditions, except for the number of handshakes, would be the one with seven rows, three seats in each row and 21 participants in total. To count the squeezes (see image) it will be necessary to take into account that the four participants of the corners only shake hands with three participants (blue lines), those that are located on the sides, which in this case are 12, shake hands 5 participants each (red lines), and those who sit in one of the remaining seats, 5 in this case, shake hands with 8 (green lines).

In total, we could say that if we add the outstretched hands that all participants give, we would have 4 * 3 + 12 * 5 + 5 * 8 = 12 + 60 + 40 = 112 hands. However, there is a small detail that must be taken into account, and that is that in each handshake two people intervene, so that only 56 squeezes are given, in reality.

This calculation is far from the 1020 of which the problem speaks to us, so in all likelihood there are more rows, or columns, or both.

Suppose we add a column of seats (that is, one more in each row). If we add it at the end or at the beginning, there will be changes in the number of hands outstretched that people who were already placed will have to offer, so that we will add it between the first and the second column, that is, we will add 2 seats first and last row and 5 of the interior seats, that is, 2 * 5 + 5 * 8 = 50 outstretched hands, or 25 more grips. Each column that we add brings, therefore, 25 handshakes, with which we would never reach 1020 (56 + n * 25 can never be 1020 for any n, as it is easy to verify).

If we increase the number of rows of the initial amount, we can only do it from 7 to 7, that is, we would add 14 seats at the beginning or end of the row and 7 interiors (again we are not supposed to add them at the end or at the beginning, to simplify the calculations). In total, it would be 14 * 5 + 7 * 8 = 126 outstretched hands, or 63 grips. In total, we would now have 119 grips. Now, increasing column by column, we add 2 * 5 + 12 * 8 = 106 hands, or 53 grips. Therefore, the number would be 119 + n * 53, with n the number of columns. If we put 1020 = 119 + n * 53, we have to n = (1020 - 119) / 53 = 901/53 = 17. That is, that with 14 rows and 20 seats per row (columns) we would have 1020 grips.