#C8776. Matrix Diagonal Sum after 90° Clockwise Rotation
Matrix Diagonal Sum after 90° Clockwise Rotation
Matrix Diagonal Sum after 90° Clockwise Rotation
Given a positive integer (N), you are required to generate an (N \times N) matrix with values from 1 to (N^2) in row-major order. Then rotate the matrix 90° clockwise and compute the sum of the main diagonal (top-left to bottom-right) and the secondary diagonal (top-right to bottom-left) of the rotated matrix. Your program should read the input from standard input and print the two sums separated by a space to the standard output.
The rotation of the matrix is defined such that each element at position (a_{ij}) in the original matrix moves to position (a_{j, N-i-1}) in the rotated matrix. For example, when (N=3), the matrix rotates as follows:
Original Matrix:\newline (\begin{bmatrix}1 & 2 & 3\4 & 5 & 6\7 & 8 & 9\end{bmatrix})
Rotated Matrix:\newline (\begin{bmatrix}7 & 4 & 1\8 & 5 & 2\9 & 6 & 3\end{bmatrix})
The sum of the main diagonal is (7+5+3=15) and the secondary diagonal is (1+5+9=15).
inputFormat
The input consists of a single integer (N) ((N \ge 1)), provided via standard input.
outputFormat
Output two space-separated integers representing the sum of the main diagonal and the sum of the secondary diagonal of the matrix after a 90° clockwise rotation.## sample
1
1 1