#include using namespace std; #define llong long long int #define ldouble long double #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, k, n) for (int i = k; i < n; ++i) #define fore(i,a) for (auto &i : a) #define repr(i, n) for (int i = n; i >= 0; --i) #define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() const static int mod = 1000000000 + 7; const static int inf = INT_MAX / 2; const static llong INF = LLONG_MAX / 2; const static double eps = 1e-10; const static int dx[] = {1, 0, -1, 0}; const static int dy[] = {0, 1, 0, -1}; signed main (int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); llong n, d; cin >> n >> d; vector XY; for (llong x = 1; x <= n; ++x) { for (llong y = 1; y <= n; ++y) { XY.push_back(x * x + y * y); } } sort(all(XY)); llong res = 0; for (llong z = 1; z <= n; ++z) { for (llong w = 1; w <= n; ++w) { llong target = w * w - z * z + d; res += upper_bound(all(XY), target) - lower_bound(all(XY), target); } } cout << res << endl; return 0; }