#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; LL maxx = std::min(N, sqrt(max)); for (LL x = 1; x <= maxx; ++x) { if (x * x > max) continue; for (LL y = x; y <= maxx; ++y) { if (x * x + y * y > max) continue; for (LL z = y; z <= maxx; ++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) { if (x == y && y == z) ans += 1; else if (x == y || x == z || y == z) ans += 3; else ans += 6; } } } } } out << ans << std::endl; }