Tablica
Ivo has an N×N table. The table has the integers 1 through N2inscribed in row-major order. The following operations can be done on the table:
1. Rotate a row – all cells in a single row are rotated right, so that the number in the last column moves to the first.
2. Rotate a column – all cells in a single column are rotated down, so that the number in the last row moves to the first. Ivo occasionally feels the urge to move a number X to cell (R, []) and proceeds as follows:
• While X is not in column C, rotate the row it is in.
• While X is not in row R, rotate the column it is in.
Here is an example of how to move number 6 to cell (3, 4), start from the initial configuration:
Ivo wants to move K numbers one after another. Write a program that calculates the number of rotations needed.
[c]4 1
6 3 4
Output:
3 Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.