#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; for (LL x = 1; x <= N; ++x) { for (LL y = 1; y <= N; ++y) { LL C = x * x + y * y; LL M = D - C; if (M == 0) { if (x == y) ans += (N - 1) * 3 + 1; else ans += (N - 2) * 6 + 2 * 3; } else { for (LL d = 1; d*d <= std::abs(M); ++d) { if (M % d != 0) continue; LL a = d, b = M / d; if (a < b) std::swap(a, b); if ((a + b) % 2 == 0) { LL z = (a + b) / 2; LL w = a - z; if (b > 0 && z < w) std::swap(z, w); if (b < 0 && z > w) std::swap(z, w); if (1 <= z && z <= N && 1 <= w && w <= N) ++ans; } } } } } out << ans << std::endl; }