N, D = map( int, input().split()) left = [0]*(8*(10**6)) right = [0]*(9*(10**6)) for i in range(1, N+1): for j in range(1, N+1): left[i**2 + j**2] += 1 for i in range(1, N+1): for j in range(1, N+1): right[i**2 - j**2 + D+4*10**6] += 1 ans = 0 for i in range(1, 8*10**6+1): if i+4*10**6 > 8*10**6: break ans += left[i]*right[i+4*10**6] print(ans)