from collections import defaultdict N,D = list(map(int,input().split())) d1 = defaultdict(int) for x in range(1,N+1): x2 = x*x for y in range(1,N+1): y2 = y*y d1[x2+y2] += 1 d2 = defaultdict(int) for w in range(1,N+1): w2 = w*w for z in range(1,N+1): z2 = z*z if(w2+D-z2 <= 0):break if(w2+D-z2 not in d1):continue d2[w2+D-z2] += 1 ans = 0 for i in d2: ans += d1[i] * d2[i] print(ans)