#K36812. Matrix Generation by Parity Rules
Matrix Generation by Parity Rules
Matrix Generation by Parity Rules
Given an integer ( n ) from standard input, generate an ( n \times n ) matrix ( M ) where each element ( M[i][j] ) (with ( 0 )-based indexing) is defined according to the following rules:
( \bullet ) If ( i = j ), then ( M[i][j] = 0 ).
( \bullet ) If ( i \neq j ):
- If both ( i ) and ( j ) are even or both are odd (i.e. they have the same parity), then ( M[i][j] = 1 ).
- Otherwise, if one is even and the other is odd, then ( M[i][j] = 2 ).
Output the matrix with each row on a new line and values separated by a space.
inputFormat
A single integer ( n ) (where ( 1 \le n \le 100 )) provided on standard input.
outputFormat
The generated ( n \times n ) matrix printed to standard output. Each row should be printed on a new line with its elements separated by a space.## sample
1
0