#include using namespace std; using ll = long long; using vi = vector; #define rep1(a) for(ll i = 0; i < ll(a); i++) #define rep2(i, a) for(ll i = 0; i < ll(a); i++) #define rep3(i, a, b) for(ll i = ll(a); i < ll(b); i++) #define rep4(i, a, b, c) for(ll i = ll(a); i < ll(b); i += ll(c)) #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define all(x) begin(x),end(x) #define rall(x) rbegin(x),rend(x) #include struct splitmix64_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template using HashMap = __gnu_pbds::gp_hash_table; template using HashSet = HashMap; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N, D; cin >> N >> D; HashMap mp; rep(x, 1, N + 1) rep(y, 1, N + 1) mp[x * x + y * y]++; ll ans = 0; rep(w, 1, N + 1) rep(z, 1, N + 1) { ll val = w * w + D - z * z; if(mp.find(val) != mp.end()) ans += mp[val]; } cout << ans << endl; }