#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
#define PB push_back
#define MP make_pair
#define st first
#define nd second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<long long>;
using ld = long double;

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int n, mod;

inline void Add(int &x, int y) {
  x += y; if (x >= mod) { x -= mod; }
}

inline void Sub(int &x, int y) {
  x -= y; if (x < 0) { x += mod; }
}

int dp[512][256];

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);

  cin >> n >> mod;

  vector<pii> steps;

  for (int step = 0; step < 2 * n; ++step) {
    const int vert = 2 * n - step - 1;

    int min_p = 0;
    while (min_p * min_p + vert * vert < n * n) { ++min_p; }

    int max_p = min_p;
    while (max_p * max_p + vert * vert <= 4 * n * n) { ++max_p; }
    --max_p;
    mini(max_p, 2 * n - 1);
    steps.emplace_back(min_p, max_p);
  }

  int ans = 0;

  for (int nend = 0; nend <= n; ++nend) {
    memset(dp, 0, sizeof(dp));

    dp[0][0] = 1;
    int ptr = 0;
    for (int i = n; i < 2 * n; ++i) {
      const int src = i - n;
      const int dst = src + 1;
      const int L = steps[i].st - 1;
      const int R = steps[i].nd;
      int cptr = ptr;

      debug(nend, i, L, R);

      for (int nsofar = 0; nsofar <= nend; ++nsofar) {
        int mul = 1;
        cptr = ptr;
        while (cptr < n && steps[cptr].nd < L) {
          mul = (ll)mul * (steps[cptr].nd - cptr - nsofar + 1) % mod;
          ++cptr;
        }

        const int val = dp[src][nsofar];
        if (!val) { continue; }
        debug(nsofar, val, mul, cptr);

        // make a flip
        int flip_coef = (ll)mul * val % mod;
        flip_coef = (ll)flip_coef * (L - cptr - nsofar + 1) % mod;
        Add(dp[dst][nsofar + 1], flip_coef);

        // no flip
        int noflip_coef = (ll)mul * val % mod;
        noflip_coef = (ll)noflip_coef * (R - i - (nend - nsofar) + 1) % mod;
        Add(dp[dst][nsofar], noflip_coef);

        debug(flip_coef, R - i);
      }

      ptr = cptr;
    }

    int coef = dp[n][nend];

    while (ptr < n) {
      coef = (ll)coef * (steps[ptr].nd - ptr - nend + 1) % mod;
      ++ptr;
    }

    debug(coef);

    if (nend % 2 == 0) {
      Add(ans, coef);
    } else {
      Sub(ans, coef);
    }
  }

  cout << ans << "\n";
}



Measured memory_bytes: 768