#include #define int long long using namespace std; int cnt1[8000001]; //x^2 + y^2 int cnt2[8000001]; //z^2 - w^2 + D int n, d; signed main() { int i, j; cin >> n >> d; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) cnt1[i * i + j * j]++; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { int x = i * i - j * j + d; if (0 <= x && x <= 2 * n * n) { cnt2[x]++; } } } int ans = 0; for (i = 0; i <= 2 * n * n; i++) ans += cnt1[i] * cnt2[i]; cout << ans << endl; return 0; }