Language: C++

/*input
3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

bool isp[maxn];
vector<int> p;

ll g[maxn][maxn];

vector<int> a,b;

ll lcm(ll a,ll b){
	if(a==0||b==0) return a+b;
	return a*b/__gcd(a,b);
}

int main()
{
	IOS;
	int N=500;

	for(int i=2;i<maxn;i++){
		if(!isp[i]) p.pb(i);
		for(int j=0;i*p[j]<maxn;j++){
			isp[i*p[j]]=1;
			if(i%p[j]==0) break;
		}
	}
	REP(i,500) a.pb(p[i]);
	REP(i,500) b.pb(p[i+500]);

	REP(i,500) REP(j,500) if((i+j)%2==0){
		g[i][j]=1;
		g[i][j]*=a[(i+j)/2];
		g[i][j]*=b[(i-j+499)/2];
	}

	REP(i,500) REP(j,500) if((i+j)%2){
		g[i][j]=0;

		if(i+1<500) g[i][j]=lcm(g[i][j],g[i+1][j]);
		if(j+1<500) g[i][j]=lcm(g[i][j],g[i][j+1]);
		if(i) g[i][j]=lcm(g[i][j],g[i-1][j]);
		if(j) g[i][j]=lcm(g[i][j],g[i][j-1]);
		g[i][j]++;
		assert(g[i][j]<1e15);
	}
	int n;
	cin>>n;
	REP(i,n) REP(j,n) cout<<g[i][j]<<" \n"[j==n-1];

	REP(i,n) REP(j,n-1) assert(max(g[i][j],g[i][j+1])%min(g[i][j],g[i][j+1])==1);

	return 0;
}


Compiler output:
/tmp/ccvhmhnK.o: in function `main':
a.cc:(.text+0x260): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccvhmhnK.o
a.cc:(.text+0x2a4): relocation truncated to fit: R_X86_64_PC32 against symbol `b' defined in .bss section in /tmp/ccvhmhnK.o
a.cc:(.text+0x32d): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccvhmhnK.o
a.cc:(.text+0x3af): relocation truncated to fit: R_X86_64_PC32 against symbol `b' defined in .bss section in /tmp/ccvhmhnK.o
/tmp/ccvhmhnK.o: in function `__static_initialization_and_destruction_0()':
a.cc:(.text+0x9d4): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccvhmhnK.o
a.cc:(.text+0x9ed): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccvhmhnK.o
a.cc:(.text+0xa06): relocation truncated to fit: R_X86_64_PC32 against symbol `b' defined in .bss section in /tmp/ccvhmhnK.o
a.cc:(.text+0xa1f): relocation truncated to fit: R_X86_64_PC32 against symbol `b' defined in .bss section in /tmp/ccvhmhnK.o
collect2: error: ld returned 1 exit status