#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<ll,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline int rd()
{
	int x=0;char c=gc();while(!isdigit(c))c=gc();
	while(isdigit(c))x=x*10+c-48,c=gc();return x;
}
const int N=505;
int n,P,ans,f[N][N];
struct st{int i,l,r;}a[N];
inline bool cmp(st a,st b)
{
	int a1=a.i<n?a.l-1:a.r;
	int a2=a.i<n?a.r:a.l-1;
	int b1=b.i<n?b.l-1:b.r;
	int b2=b.i<n?b.r:b.l-1;
	return a1!=b1?a1<b1:(a2!=b2?a2<b2:a.i>b.i);
}
inline int calc(int k)
{
	memset(f,0,sizeof(f));f[0][0]=1;int s=0;
	rep(i,1,2*n)
	{
		rep(j,0,k)if(f[i-1][j])
		{
			int w=f[i-1][j];
			if(a[i].i>=n)
			{
				int c=a[i].r+1-(i-1-(s-j));
				if(c>0)f[i][j]=(f[i][j]+1ll*w*c)%P;
			}
			else
			{
				int c=a[i].r+1-(2*n-a[i].i-1+k-j);
				if(c>0)f[i][j]=(f[i][j]+1ll*w*c)%P;
				c=a[i].l-(i-1-(s-j));
				if(c>0)f[i][j+1]=(f[i][j+1]+1ll*w*c)%P;
			}
		}
		s+=a[i].i<n;
	}
	return f[2*n][k];
}
int main()
{
	n=rd();P=rd();
	rep0(i,0,2*n)
	{
		a[i+1].i=i;if(i<n)a[i+1].l=ceil(sqrt(n*n-i*i));
		a[i+1].r=floor(sqrt(4*n*n-i*i));a[i+1].r=min(a[i+1].r,2*n-1);
	}
	sort(a+1,a+2*n+1,cmp);
	rep(i,0,n)ans=(ans+1ll*(i&1?P-1:1)*calc(i))%P;
	printf("%d\n",ans);return 0;
}
