#include using namespace std; using ll = long long; int cnt1[10000000]; int cnt2[10000000]; int main(){ int n, d; cin >> n >> d; for(int x = 1; x <= n; x++){ for(int y = 1; y <= n; y++){ cnt1[x*x+y*y]++; } } for(int z = 1; z <= n; z++){ for(int w = 1; w <= n; w++){ if(-z*z+w*w+d<0) continue; cnt2[-z*z+w*w+d]++; } } int ans = 0; for(int i = 0; i < 1e7; i++){ ans += cnt1[i]*cnt2[i]; } cout << ans << endl; return 0; }