// #define _GLIBCXX_DEBUG // for STL debug (optional) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define debug(...) fprintf(stderr, __VA_ARGS__) #define int long long int template void chmax(T &a, T b) {a = max(a, b);} template void chmin(T &a, T b) {a = min(a, b);} template void chadd(T &a, T b) {a = a + b;} typedef pair pii; typedef long long ll; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const ll INF = 1001001001001001LL; const ll MOD = 1000000007LL; signed main() { int N, D; cin >> N >> D; map lhs; vector rhs; for(int i=1; i<=N; i++) { for(int j=1; j<=N; j++) { lhs[i*i + j*j]++; rhs.push_back(i*i - j*j + D); } } sort(rhs.begin(), rhs.end()); // fprintf(stderr, "sort end\n"); int ans = 0; for(auto e : lhs) { int x = e.first, y = e.second; int il = lower_bound(rhs.begin(), rhs.end(), x) - rhs.begin(); int ir = upper_bound(rhs.begin(), rhs.end(), x) - rhs.begin(); ans += (ir - il) * y; } cout << ans << endl; return 0; }