#include<bits/stdc++.h>
using namespace std;

int n,mod,l[510],r[510],f[261][261][261],la,p,nw,ans;

int main()
{
	scanf("%d%d",&n,&mod);
	l[0]=n,r[0]=2*n-1;
	for (int i=1; i<2*n; i++)
	{
		l[i]=l[i-1],r[i]=r[i-1];
		while (l[i]&&(l[i]-1)*(l[i]-1)+i*i>=n*n) l[i]--;
		while (r[i]*r[i]+i*i>4*n*n) r[i]--;
	}
	la=2*n;
	for (int i=0; i<=n; i++) f[n][0][i]=1;
	for (int i=n-1; i>=0; i--)
	{
		for (int j=0; j<=n-i-1; j++)
		{
			p=la,nw=1;
			while (r[p-1]<l[i]) nw=1ll*nw*(r[p-1]+1-(j+(2*n-p)))%mod,p--;
			f[i][j][j]=(f[i][j][j]+1ll*nw*(r[i]+1-(2*n-1-i))%mod*f[i+1][j][j])%mod;
			for (int k=j+1; k<=n; k++)
				f[i][j+1][k]=(f[i][j+1][k]+1ll*nw*(l[i]-j-(2*n-p))%mod*f[i+1][j][k])%mod,
				f[i][j][k]=(f[i][j][k]+1ll*nw*(r[i]+1-(k-j+(2*n-1-i)))%mod*f[i+1][j][k])%mod;
		}
		la=p;
	}
	ans=0;
	for (int i=0; i<=n; i++) 
	{
		nw=1;
		for (int j=n; j<la; j++) nw=1ll*nw*(r[j]+1-(i+(2*n-j-1)))%mod;
		if (i&1) ans=(ans+1ll*(mod-nw)*f[0][i][i])%mod;
		else ans=(ans+1ll*nw*f[0][i][i])%mod;
	}
	return printf("%d\n",ans),0;
}