#include using namespace std; using ll = long long; using P = pair; using T = tuple; #define al(a) a.begin(), a.end() #define ral(a) a.rbegin(), a.rend() #define sz(a) (int)a.size() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define db(a, b) cout << #a << ": " << a << " " << #b << ": " << b << endl; int main() { ll n, d; cin >> n >> d; unordered_map mp; for (int x = 1; x <= n; ++x) { for (int y = 1; y <= n; ++y) { int s = x * x + y * y; mp[s]++; } } ll ans = 0; for (int z = 1; z <= n; ++z) { for (int w = 1; w <= n; ++w) { int t = w * w - z * z + d; ans += mp[t]; } } cout << ans << endl; return 0; }