#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<ll,ll>
#define vint vector<ll>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const ll N=505;
struct node{ll p,id;}a[N];
ll f[N][N],n,mod,l[N],r[N],cnt,ans;
ll solve(ll k){
	memset(f,0,sizeof(f));cnt=0;f[0][0]=1;
	for(ll i=1;i<=n<<1;i++){
		if(a[i-1].id<n)cnt++;
		for(ll j=0;j<=k;j++){
			if(a[i-1].id<n){
				f[i][j]=f[i-1][j]*(r[a[i-1].id]+1-((n<<1)-1-a[i-1].id+k-j))%mod;
				if(j)f[i][j]=(f[i][j]+f[i-1][j-1]*(a[i-1].p+1-(i-1-(cnt-j)))%mod)%mod;
			}else f[i][j]=f[i-1][j]*(a[i-1].p+1-(i-1-(cnt-j)))%mod;
		}
	}return f[n<<1][k];
}
signed main(){
	n=read(),mod=read();
	for(ll i=0;i<n<<1;i++){
		a[i].id=i;r[i]=min((n<<1)-1,(ll)floor(sqrt(4*n*n-i*i)));
		if(i>=n)a[i].p=r[i];else l[i]=ceil(sqrt(n*n-i*i)),a[i].p=l[i]-1;
	}sort(a,a+(n<<1),[](node a,node b){return a.p==b.p?a.id>b.id:a.p<b.p;});
	for(ll i=0;i<=n;i++)ans=(ans+(i&1?mod-1:1)*solve(i)%mod)%mod;
	return cout<<ans,signed();
}
/*
2 998244353
10 998244353
200 998244353
*/