TOJ 2968. Find the Diagonal

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.

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 23

81 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值