Python3 代码
n, m = input().split()
m = int (m)
n = int (n)
l = [[0]* m for i in range (n)]
x = y = 0
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
d = 1
for i in range (1, m * n + 1):
l [x][y] = i
a = x + dx[d]
b = y + dy[d]
if a<0 or a>=n or b<0 or b>=m or l[a][b]>0:
d = (d + 1) % 4
a = x + dx[d]
b = y + dy[d]
x = a
y = b
for i in range (n):
for j in range (m):
print (l[i][j], end = " ")
print ("")