#include #define rep(i,n) for(int i=0;i<(n);++i) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair P; typedef pair PP; vector

div(int n){ vector

res; res.clear(); for (int i = 1; i * i <= n; ++i){ if (n % i == 0){ if (i * i != n){ int a = i; int b = n / i; if ((a % 2 != 0) && (b % 2 == 0)) continue; if ((a % 2 == 0) && (b % 2 != 0)) continue; res.push_back(P(i, n/i)); res.push_back(P(n/i, i)); }else{ res.push_back(P(i,i)); } // end if } // end if } // end for return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N, D; cin >> N >> D; set res; res.clear(); for (int x = 1; x <= N; ++x){ for (int y = 1; y <= N; ++y){ int x2y2 = x * x + y * y; int sign = (x2y2 - D < 0 ? -1 : 1); int X = abs(x2y2 - D); if (X == 0){ for (int i = 1; i <= N; ++i){ res.insert(PP(P(x,y), P(i,i))); } // end for continue; } // end if vector

ans = div(X); int m = (int)ans.size(); // cerr << "m: " << m << endl; rep (i, m){ int a = ans[i].first; int b = ans[i].second; int w = (a + b) / 2; int z = (a - b) / 2; if (w >= 1 && z >= 1 && w <= N && z <= N && x2y2 + z * z == w * w + D){ // cerr << x << ' ' << y << ' ' << z << ' ' << w << endl; res.insert(PP(P(x,y),P(z,w))); } // end if } // end rep if (sign < 0){ rep (i, m){ int a = ans[i].first; int b = sign * ans[i].second; int w = (a + b) / 2; int z = (a - b) / 2; if (w >= 1 && z >= 1 && w <= N && z <= N && x2y2 + z * z == w * w + D){ // cerr << x << ' ' << y << ' ' << z << ' ' << w << endl; res.insert(PP(P(x,y),P(z,w))); } // end if } // end rep } // end if } // end for } // end for cout << (int)res.size() << endl; return 0; }