Răspuns:
#include<iostream>
using namespace std;
int main(){
int n, k, v[101][101],i,j;
cin>>n>>k;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(i==j || j==n-i+1){
v[i][j] = 1;
}
else{
int nr=1,c=0;
while(nr!=k+1){
if(j==i+nr || j==i-nr || j==n-i+1+nr || j==n-i+1-nr){
v[i][j] = 1;
c++;
break;
}
nr++;
}
if(c==0){
v[i][j] = 2;
}
}
}
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
cout<<v[i][j]<<" ";
}
cout<<endl;
}
return 0;
}