N, D = map(int, input().split()) ans = 0 p = [] cnt =[0] * (8 * 10**6 + 1) ## x*x + y*y = s for i in range(1, N+1): p.append(i*i) for z in p: for w in p: s = w - z + D if s >= 0: cnt[s] += 1 for x in p: for y in p: ans += cnt[x+y] print(ans)