#include using namespace std; typedef long long ll; #define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) int main() { int n,d; cin >> n >> d; int m = max(2*n*n+1,n*n+d+1); vector a(m,0),b(m,0); for (int i = 1;i <= n;++i) for (int j = 1;j <= n;++j) a[i*i+j*j]++; for (int i = 1;i <= n;++i) for (int j = 1;j <= n;++j) if (i*i-j*j+d > 0) b[i*i-j*j+d]++; ll ans = 0; for (int i = 1;i < m;++i) ans += a[i]*b[i]; cout << ans << endl; return 0; }