#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include using namespace std; #include using namespace atcoder; #define REP(i, n) for(int i = 0; i < (int)n; i++) #define LREP(i, n) for(LL i = 0; i < (LL)n; i++) #define RREP(i, n) for(int i = (int)n-1; i >= 0; i--) #define V(T) vector #define P pair #define LP pair #define T3 tuple #define T4 tuple #define INF 1000000007 #define SIZE 500100 #define MOD 1000000007 typedef long long LL; #define SIZE2 2010 LL N, D; LL C[2 * SIZE2 * SIZE2]; int main() { cin >> N >> D; for (LL x = 1; x <= N; x++) { for (LL y = 1; y <= N; y++) { C[x * x + y * y] += 1; } } LL ans = 0; for (LL z = 1; z <= N; z++) { for (LL w = 1; w <= N; w++) { LL Y = D + w * w - z * z; if (0 <= Y && Y <= 2 * N * N) { ans += C[Y]; } } } cout << ans << endl; }