#include #include using lint = long long; constexpr int N = 2000 * 2000 * 2; void solve() { int n, d; std::cin >> n >> d; std::vector cnt(N + 1, 0); for (int x = 1; x <= n; ++x) { for (int y = 1; y <= n; ++y) { ++cnt[x * x + y * y]; } } lint ans = 0; for (int z = 1; z <= n; ++z) { for (int w = 1; w <= n; ++w) { lint rhs = w * w - z * z + d; if (0 <= rhs && rhs <= N) ans += cnt[rhs]; } } std::cout << ans << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }