728x90
#include <iostream>
#include <vector>
using namespace std;
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
int main() {
int i, j;
int n,target;
cin >> n;
cin >> target;
vector<vector<int>>arr(n, vector<int>(n));
i = n / 2;
j = n / 2;
int num = 1;
int total = n*n;
int p = 1;
int ax = 0;
int ay = 0;
int dir = 0;
while (num != total) {
for (int t = 0; t < 2; t++) {
for (int k = 0; k < p; k++) {
arr[i][j] = num;
if (num ==target ) { ax = i+1; ay = j+1; }
i = i + dx[dir];
j = j + dy[dir];
num++;
if (num > total) { goto next; }
}
dir++;
if (dir > 3) { dir = 0; }
}
p++;
}
next:
for (int r = 0; r < n; r++) {
for (int q = 0; q < n; q++) {
cout << arr[r][q]<<" ";
}
cout << endl;
}
cout << ax << " " << ay << endl;
}