#include using namespace std; using ll = long long; const ll mod = 1e9 + 7; const ll inf = (1 << 30) - 1; const ll infll = (1LL << 61) - 1; ll n, d, ans; map Y; int main() { cin >> n >> d; vector X(3 * n * n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { X[i * i + j * j]++; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { Y[i * i - j * j]++; } } for (int i = 1; i <= 2 * n * n; i++) { if (Y.find(d - i) != Y.end()) continue; ans += X[i] * Y[d - i]; //printf("X:%d Y:%d i:%d\n", X[i], Y[d - i], i); } cout << ans << endl; }