A square matrix contains equal number of rows and columns. If the order of the matrix is known it can be calculated as in the following format:
Order: 3
Order: 5
and so on..
Now look at the diagonals of the matrices. In the second matrix - the elements of a diagonal are marked with circles but this is not the only one in this matrix but there are some other minor diagonals like <6, 12, 18, 24> as well as <2, 8, 14, 20> and many others.
Order: 3
![](https://i-blog.csdnimg.cn/blog_migrate/ff11f18b9034637c4b4196bcd0e055e0.png)
Order: 5
![](https://i-blog.csdnimg.cn/blog_migrate/8b5d440bd1b834c69d844ce1af6c9f6f.png)
and so on..
Now look at the diagonals of the matrices. In the second matrix - the elements of a diagonal are marked with circles but this is not the only one in this matrix but there are some other minor diagonals like <6, 12, 18, 24> as well as <2, 8, 14, 20> and many others.
Input
Each input line consists of two values. The first value is the order of the matrix and the later is an arbitrary element of that matrix. The maximum element of the matrix will fit as a 32-bit integer.Output
Each output line will display the diagonal elements of the matrix containing the given input element.Sample Input
4 5 5 11 10 81
Sample Output
5 10 15 11 17 2381 92
#include<iostream> using namespace std; int main(){ int n,m,r; while(cin>>n>>m){ r=n+1; while(m%n!=1&&m>n) m=m-r; cout<<m; //m=m+r; while(m+r<=n*n&&m%n!=0){ m=m+r; cout<<" "<<m; //m=m+r; } cout<<endl; } return 0; }