#include #include #include #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { int n, d; cin >> n >> d; vector sq(n * n + 1, false); for (int i = 1; i <= n; i++) { sq[i * i] = true; } int ans = 0; for (int x = 1; x <= n; x++) { for (int y = 1; y <= n; y++) { for (int z = 1; z <= n; z++) { auto w2 = x * x + y * y + z * z - d; if (0 <= w2 and w2 <= n * n and sq[w2]) ans++; } } } cout << ans << endl; return 0; }