#include #define rep(i,n) for(int i=0;i ; const int INF = 1e9; const int MOD = 1000000007; const ll MX = 8000005; int main(){ ll n,d; cin >> n >> d; vector a(MX,0); for(ll i=1;i<=n;i++){ ll res = i * i; for(ll j=1;j<=n;j++){ a[res+j*j] ++; } } ll ans = 0; for(ll i=1;i<=n;i++){ ll res = i * i; for(ll j=1;j<=n;j++){ ll c = res + d - j*j; if(c < 0 || c >= MX) continue; ans += a[c]; } } cout << ans << endl; return 0; }