#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=260;

int n,mod;

int l[maxn],r[maxn];
int R[maxn];

inline void init()
{
	n=read();mod=read();
	REP(i,0,n-1)
	{
		l[i+1]=sqrt(n*n-i*i-1)+1;
		r[i+1]=min((int)sqrt(4*n*n-i*i),2*n-1)+1;
	}
	REP(i,0,n-1)R[i+1]=sqrt(4*n*n-(i+n)*(i+n))+1;
}

int dp[maxn],g[maxn];

inline void doing()
{
	int ans=0;
	REP(t,0,n)
	{
		memset(dp,0,sizeof(dp));
		dp[0]=1;
		int sum1=0,sum2=0;
		for(int i=n,j=n;i>0 || j>0;)
		{
			memset(g,0,sizeof(g));
			if(j==0 || (i>0 && l[i]<R[j]))
			{
				REP(k,0,t)
				{
					if(k<t)g[k+1]=(g[k+1]+(ll)dp[k]*max(l[i]-sum2-k,0))%mod;
					g[k]=(g[k]+(ll)dp[k]*max(r[i]-n-sum1-(t-k),0))%mod;
				}
				sum1++;
				i--;
			}else
			{
				REP(k,0,t)
				{
					g[k]=(g[k]+(ll)dp[k]*(R[j]-k-sum2))%mod;
				}
				sum2++;
				j--;
			}
			memcpy(dp,g,sizeof(g));
		}
		ans=(ans+(t&1?-1:1)*dp[t])%mod;
	}
	ans=(ans+mod)%mod;
	printf("%d\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}
