#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i,N) for(LL i=0;i> N >> D; LL ans = 0, max = N * N + D; for (LL x = 1; x <= N; ++x) { if (x*x > max) continue; for (LL y = 1; y <= N; ++y) { if (x*x + y * y > max) continue; for (LL z = 1; z <= N; ++z) { if (x*x + y * y + z * z > max) continue; LL w2 = x * x + y * y + z * z - D; if (w2 > 0) { LL w = sqrt(w2); if (w*w == w2) ++ans; } } } } out << ans << std::endl; }