// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define nn 502

#define int long long

int n,mod;int dp[nn][nn];

int li[nn],ri[nn];

int id[nn];

#define pii pair<int,int>

#define mp make_pair

pii make(int x){

	if(li[x]) return mp(li[x]-1,ri[x]);

	else return mp(ri[x],li[x]); 

}

int cmp(int x,int y){

	return make(x)<make(y);

}

void add(int &x,int y){

	x=(x+y)%mod;

}



int solve(int diss){

	memset(dp,0,sizeof dp);dp[0][0]=1;int cnt=0,tnc=0;;

	for(int i=0;i<n;i++){

		int x=id[i];

		if(li[x]){

			for(int j=0;j<=diss;j++){

				add(dp[i+1][j],dp[i][j]*max(0ll,ri[x]+1-n/2-tnc-(diss-j)));

				add(dp[i+1][j+1],dp[i][j]*max(0ll,li[x]-j-cnt));

			}

			tnc++;

		}

		else{

			for(int j=0;j<=diss;j++) add(dp[i+1][j],dp[i][j]*max(0ll,ri[x]-j-cnt+1));

			++cnt;

		}

	}

//	cout<<dp[n][diss]<<" ";

	return dp[n][diss];

}

signed main(){

	scanf("%lld%lld",&n,&mod);n=n*2;

	for(int i=0;i<n;i++){

		li[i]=-1,ri[i]=n,id[i]=i;

		for(int j=0;j<n;j++) if(i*i+j*j<n*n/4) li[i]=j;li[i]++;

		for(int j=n-1;j>=0;j--) if(i*i+j*j>n*n) ri[i]=j;ri[i]--;

	//s	cout<<li[i]<<" "<<ri[i]<<"\n";

	}

	

	sort(id,id+n,cmp);

	

	int flg=1,ans=0;

	for(int diss=0;diss<=n/2;diss++,flg=-flg)

		ans=(ans+flg*solve(diss))%mod;

	ans+=mod;ans%=mod;

	printf("%lld\n",ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cmath>

#include <cstdio>

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

#define N 505

#define ll long long

#define inf 0x3f3f3f3f

void Read(int &p)

{

	p = 0;

	char c = getchar();

	for (; c < '0' || c > '9'; c = getchar());

	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';

}

int dp[N][N], n, mod, ans;

void Upd(int &x, int y){x = x + y >= mod ? x + y - mod : x + y;}

struct Node

{

	int d, l, r;

}A[N];

bool cmp(Node A, Node B)

{

	int a1 = A.d < n ? A.l - 1 : A.r;

	int a2 = A.d < n ? A.r : A.l - 1;

	int b1 = B.d < n ? B.l - 1: B.r;

	int b2 = B.d < n ? B.r : B.l - 1;

	return a1 != b1 ? a1 < b1 : a2 != b2 ? a2 < b2 : A.d > B.d;

}

int Solve(int k)

{

	memset(dp, 0, sizeof(dp));

	int sum = 0;

	dp[0][0] = 1;

	for (int i = 1; i <= 2 * n; i++)

	{

		for (int j = 0; j <= k; j++)

		{

			if (A[i].d >= n)

			{

				int c = A[i].r + 1 - (i - 1 - (sum - j));

				if (c > 0)

					Upd(dp[i][j], 1ll * dp[i - 1][j] * c % mod);

			}

			else

			{

				int c = A[i].r + 1 - (2 * n - A[i].d - 1 + k - j);

				if (c > 0)

					Upd(dp[i][j], 1ll * dp[i - 1][j] * c % mod);

				if (j)

				{

					c = A[i].l - (i - 1 - (sum - j + 1));

					if (c > 0)

						Upd(dp[i][j], 1ll * dp[i - 1][j - 1] * c % mod);

				}

			}

		}

		sum += A[i].d < n;

	}

	return dp[n << 1][k];

}

int main()

{

	Read(n), Read(mod);

	for (int i = 0; i < 2 * n; i++)

	{

		A[i + 1].d = 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);

	for (int i = 0; i <= n; i++)

	{

		if (i & 1)

			Upd(ans, mod - Solve(i));

		else

			Upd(ans, Solve(i));

	}

	printf("%d\n", ans);

}


// Fastest known solution for this problem: