#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, d; cin >> n >> d; vector p, q; for (int x = 1; x <= n; x++) { for (int y = 1; y <= n; y++) { p.push_back(x*x + y*y); } } for (int z = 1; z <= n; z++) { for (int w = 1; w <= n; w++) { q.push_back(z*z - w*w); } } sort(q.begin(), q.end()); long long ret = 0; for (int x: p) { int target = d - x; ret += upper_bound(q.begin(), q.end(), target) - lower_bound(q.begin(), q.end(), target); } cout << ret << endl; return 0; }