#include #define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i ) #define rep(i,n) REP(i,0,n) using namespace std; int main(){ long N, D; cin >> N >> D; long p[2001]; int c[8000001]; REP(i, 1, N + 1){ p[i] = i*i; } REP(i, 1, N + 1)REP(j, 1, N + 1){ int s = p[i] - p[j] + D; if (s >= 1) { c[s] += 1; } } long ans; REP(i, 1, 2001)REP(j, 1, 2001){ ans += c[p[i]+p[j]]; } cout << ans ; }