#include typedef long long ll; #define rep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define print2(x,y) cout << (x) << " " << (y) << endl; #define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];} #define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl; #define INF (1e18 + 7) using namespace std; const ll MOD = 1e9 + 7; typedef pair lpair; ll cnt[8000010] = {}; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N,D; cin >> N >> D; rep(x,1,N+1){ rep(y,1,N+1){ cnt[x*x+y*y]++; } } ll ans = 0; rep(z,1,N+1){ rep(w,1,N+1){ ll v = D + w*w - z*z; if(v <= 0) continue; ans += cnt[v]; } } print(ans); }