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) cB = [0]*(2*ADD) for z in range(1, N+1): for w in range(1, N+1): cB[z**2 - w**2 + ADD] += 1 ans = 0 for a in A: if 0 <= D - a + ADD < 2*ADD: ans += cB[D-a + ADD] print(ans) if __name__ == '__main__': main()