#include using i64 = long long; constexpr int N = 1e6 + 7; int n, k; i64 cnt[N << 2]; std::vector vec; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); // freopen("alive.in", "r", stdin); // freopen("alive.out", "w", stdout); std::cin >> n >> k; memset(cnt, -1, sizeof(cnt)); for (int x = 1; x <= n; x++) { for (int y = 1; y <= n; y++) { i64 z = 1ll * x * x - 1ll * y * y + k; vec.push_back(z); } } std::sort(vec.begin(), vec.end()); i64 ans = 0; for (int x = 1; x <= n; x++) { for (int y = 1; y <= n; y++) { i64 z = x * x + y * y; if (cnt[z] != -1) ans += cnt[z]; else { auto it0 = std::lower_bound(vec.begin(), vec.end(), z); auto it1 = std::upper_bound(vec.begin(), vec.end(), z); i64 d = it1 - it0; ans += d; cnt[z] = d; } } } std::cout << ans << "\n"; return 0; }