ADD = 4*10**6 def main(): N, D = (int(i) for i in input().split()) A = [] for x in range(1, N+1): for y in range(1, N+1): A.append(x**2 + y**2) B = [] for z in range(1, N+1): for w in range(1, N+1): B.append(z**2 - w**2) ans = 0 cB = [0]*(2*ADD) for b in B: cB[b + ADD] += 1 for a in A: if 0 <= D - a + ADD < 2*ADD: ans += cB[D-a + ADD] print(ans) if __name__ == '__main__': main()