#include using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, D; cin >> N >> D; int cnt = 0; const int NN = N * N; int h, t, g, m; for (int x = 1; x <= N; x++) { g = x * x; for (int y = x ; y <= N; y++) { h = g + y * y - D; if (h > NN) break; if (h < 0) { m = max((int)sqrt(-h), y); } else { m = y; } for (int z = m; z <= N; z++) { t = h + z * z; if (t > NN) break; if (t <= 0) continue; int k = sqrt(t); if (k * k == t) { if (x != y && y != z) cnt += 6; else if (x == y && y != z) cnt += 3; else if (x != y && y == z) cnt += 3; else cnt += 1; } } } } cout << cnt << "\n"; return 0; }