#include using namespace std; typedef long long int ll; ll MOD = 1000000007; ll INFL = 1ll << 60; ll INF = 1 << 30; #define CONTAINS(v, x) (v.find(x) != v.end()) // =============================================================================== int main() { ll n, d; cin >> n >> d; map right; //(w+z)(w-z)+D for (int w = 1; w <= n; w++) { for (int z = 1; z <= n; z++) { int r = w * w - z * z + d; right[r]++; if (r <= 0) break; } } ll ans = 0; // x^2+y^2 for (int x = 1; x <= n; x++) { for (int y = x; y <= n; y++) { ll l = x * x + y * y; if (CONTAINS(right, l)) { ans += right.find(l)->second * ((x == y) ? 1 : 2); } } } cout << ans << endl; }