#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; const int MAX_N2 = (int)5e6 + 1; int cnt1[MAX_N2]; int cnt2[MAX_N2]; int main() { memset(cnt1, 0, sizeof(cnt1)); memset(cnt2, 0, sizeof(cnt2)); ios_base::sync_with_stdio(0); cin.tie(0); int N, D; cin >> N >> D; for (int x = 1; x <= N; ++x){ for (int y = 1; y <= N; ++y){ ++cnt1[x*x + y*y]; } // end for } // end for for (int w = 1; w <= N; ++w){ for (int z = 1; z <= N; ++z){ int i = w * w - z * z + D; if (i >= 0){ ++cnt2[i]; } // end if } // end for } // end for ll res = 0LL; rep (i, MAX_N2){ res += (ll)cnt1[i] * cnt2[i]; } // end rep cout << res << endl; return 0; }