#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; int memo[5000005]; int main(){ int N, D; cin >> N >> D; REP(w,1,N+1){ REP(z,1,N+1){ ll ww = w * (ll)w; ll zz = z * (ll)z; ll ans = ww-zz+D; if(1<=ans && ans<=5000000){ memo[ans]++; } } } ll ret = 0; REP(x,1,N+1){ REP(y,1,N+1){ ll xx = x * (ll)x; ll yy = y * (ll)y; ll ans = xx+yy; if(1<=ans && ans<=5000000){ ret += memo[ans]; } } } cout << ret << endl; return 0; }