This is from the old problem of the practice of the Olympiad:
Imagine that you have a 1000x1000 grid in which cell (i, j) contains the number i * j. (Rows and columns are numbered starting with 1.)
At each step, we build a new grid from the old one, in which each cell (i, j) contains a "neighborhood average" (i, j) in the last grid. "Average average" is defined as the floor of the average values of the cell and its up to 8 neighbors. So, for example, if the 4 digits in the corner of the grid were 1,2,5,7, in the next step the angle would be calculated as (1 + 2 + 5 + 7) / 4 = 3.
In the end, we will reach the point where all numbers coincide, and the grid no longer changes. The goal is to find out how many steps are required to achieve this goal.
I tried just to simulate it, but it does not work, because it seems that the answer is O (n ^ 2) steps, and each simulation step takes O (n ^ 2) for processing, resulting in O (n ^ 4) which is too small for n = 1000.
Is there a faster way to do this?
source
share