Problem 5.3. Petya and Vasya were playing with toy soldiers. Petya arranged his knights in a "rectangle" - some number of columns and some number of rows. When all the knights from the first and second rows went on reconnaissance, 24 knights remained. Then Vasya's archers drove away all the knights who were left in the first and second columns. After this, 18 knights remained. How many knights did Petya have initially?
Answer: 40.

Solution. The archers routed $24-18=6$ knights. This is two columns. So, at that moment, there were 3 knights in each column. That means 24 knights stood in 8 columns, with 3 knights in each. It follows that 16 knights (two rows, 8 knights in each) went on reconnaissance (Fig. 1).

![](https://cdn.mathpix.com/cropped/2024_05_06_32e5791ee8081231aabeg-3.jpg?height=323&width=517&top_left_y=293&top_left_x=468)

Fig. 1: To the solution of problem 5.3. Blue marks the knights who went on reconnaissance, and red marks the routed knights.

In total, Petya initially had $24+16=40$ knights.