#include #include #include using namespace std; using ll = long long; void ins() {} templatevoid ins(T& v,Rest&... rest){cin>>v;ins(rest...);} #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) for(int i=0,_i=(n);i<_i;++i) #define _rep3(i,a,b) for(int i=(a),_i=(b),_ii=(b)>(a)?1:-1;abs(_i-i)>0;i+=_ii) #define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__) int main() { int N, D; ins(N, D); map m, m2; m2[0] += N; rep(i, N) { ++m[2*(i+1)*(i+1)]; rep(j, i+1, N) { m[(i+1)*(i+1)+(j+1)*(j+1)] += 2; ++m2[(i+1)*(i+1)-(j+1)*(j+1)]; ++m2[(j+1)*(j+1)-(i+1)*(i+1)]; } } ll ans = 0; if (m2.size() < m.size()) for (const auto& [wz, count]:m2) ans += m[wz+D] * count; else for (const auto& [xy, count]:m) ans += m2[xy-D] * count; cout << ans << endl; return 0; }