#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n, m, a[501][501], val = 0, d = 2;
cin >> n >> m;
for (int i = n; i >= 1; --i)
{
for (int j = m; j >= 1; --j)
{
if (i == n && j == m)
{
a[i][j] = val;
continue;
}
val = d * d;
if (d == sqrt(val))
{
a[i][j] = val;
}
d += 2;
}
}
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
cout << a[i][j] << " ";
}
cout << '\n';
}
return 0;
}
Explicatie: