import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


struct ModInt {
  static long M;
  long x;
  this(in ModInt a) { x = a.x; }
  this(in long a) { x = a % M; if (x < 0) x += M; }
  ref ModInt opAssign(in long a) { return this = ModInt(a); }
  ref ModInt opOpAssign(string op)(in ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x *= a.x; x %= M; }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(in long a) { return mixin("this " ~ op ~ "= ModInt(a)"); }
  ModInt opUnary(string op)() const if (op == "-") { return ModInt(-x); }
  ModInt opBinary(string op, T)(in T a) const { return mixin("ModInt(this) " ~ op ~ "= a"); }
  ModInt opBinaryRight(string op)(in long a) const { return mixin("ModInt(a) " ~ op ~ "= this"); }
  string toString() const { return x.to!string; }
}


void main() {
  try {
    for (; ; ) {
      const N = readInt();
      ModInt.M = readLong();
      
      auto as = new int[2 * N];
      auto bs = new int[2 * N];
      as[] = 2 * N;
      bs[] = -1;
      foreach (i; 0 .. 2 * N) {
        foreach (x; 0 .. 2 * N) {
          if (N^^2 <= i^^2 + x^^2 && i^^2 + x^^2 <= (2 * N)^^2) {
            chmin(as[i], x);
            chmax(bs[i], x);
          }
        }
      }
      bs[] += 1;
      debug {
        writeln("N = ", N);
        if (N <= 10) {
          writeln("as = ", as);
          writeln("bs = ", bs);
        }
      }
      
      auto es = new int[N + 1];
      es[0] = N;
      foreach (i; 0 .. N) {
        es[i + 1] = bs.binarySearch!(b => (b < as[i]));
      }
      debug {
        if (N <= 10) {
          writeln("  es = ", es);
        }
      }
      
      ModInt ans;
      foreach (k; 0 .. N + 1) {
        auto dp = new ModInt[][](N + 1, N + 1);
        dp[0][0] = 1;
        foreach (i; 0 .. N) {
          foreach (j; 0 .. N) {
            ModInt d = dp[i][j];
            foreach (ii; es[i] .. es[i + 1]) {
              d *= max(bs[ii] - (2 * N - 1 - (ii - (k - j))), 0);
            }
            // bs[i]
            dp[i + 1][j] += d * max(bs[i] - (2 * N - 1 - (i - j)), 0);
            // as[i]
            dp[i + 1][j + 1] += d * max(as[i] - (2 * N - 1 - (es[i + 1] - (k - j))), 0);
          }
        }
        ans += ((k % 2 != 0) ? -1 : +1) * dp[N][k];
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 8828