#include <bits/stdc++.h>

const int MAXN = 510;
struct node {
	int typ, vl, vr;
	friend bool operator < (node a, node b) {
		return a.vl == b.vl ? a.vr < b.vr : a.vl < b.vl;
	}
} qs[MAXN];

int n, mod, bak;
typedef long long LL;
void reduce(int & x) { x += x >> 31 & mod; }
int mul(int a, int b) { return (LL) a * b % mod; }
int reduv(int a) { return a < 0 ? 0 : a; }
const double eps = 1e-8;
int dp[MAXN][260];
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0); std::cout.tie(0);
	std::cin >> n >> mod;
	for (int i = 0; i < n * 2; ++i) {
		int l = i < n ? ceil(sqrt(n * n - i * i) - eps) : -1;
		int r = floor(sqrt(n * n * 4 - i * i) + eps);
		r = std::min(r, n * 2 - 1);
		if (i < n) qs[bak++] = (node) {1, l - 1, r};
		else qs[bak++] = (node) {0, r, 0};
	}
	std::sort(qs, qs + bak);
	int ans = 0;
	for (int fin = 0; fin <= n; ++fin) {
		memset(dp, 0, sizeof dp);
		dp[0][0] = 1; int now = 0;
		for (int i = 0; i < n * 2; ++i) {
			for (int j = std::min(fin, i); ~j; --j)
				if (int t = dp[i][j]) {
					int used = now + j;
					reduce(dp[i + 1][j + qs[i].typ] += mul(t, reduv(qs[i].vl - used + 1)) - mod);
					if (qs[i].typ == 1) {
						int u2 = n + fin + i - now - j;
						reduce(dp[i + 1][j] += mul(t, reduv(qs[i].vr - u2 + 1)) - mod);
					}
				}
			now += qs[i].typ ^ 1;
		}
		reduce(ans += mul(dp[n * 2][fin], fin & 1 ? mod - 1 : 1) - mod); 
	}
	std::cout << ans << std::endl;
	return 0;
}
