#include using namespace std; using ll = long long; int main() { int n, d; cin >> n >> d; unordered_map l, r; for(int a = 1; a <= n; ++a) { for(int b = 1; b <= n; ++b) { l[a * a + b * b] += 1; r[a * a - b * b + d] += 1; } } ll ans = 0; for(auto const& p : l) { if(r.count(p.first) == 0) continue; ans += p.second * r[p.first]; } cout << ans << endl; }