In this paper, we prove that every 3-coloring of the positive integers such that the upper density of each color is greater than 1 4 contains a rainbow solution to a b D c 2 . A solution is rainbow if all of its elements are of different colors. Furthermore, the 1 4 bound is sharp. We also prove two results for rainbow solutions of a b D c 2 in Z n . One stipulates that if Z n , for an odd n, is partitioned into three color classes R; B; G with min¹jRj; jBj; jG jº > n r 1 , where r 1 is the smallest prime factor of n, then there must always exist a rainbow solution to a b c 2 mod n. Our second theorem in Z n extends this, demonstrating that if we have min¹jRj; jBj; jG jº > n 2r 1 , then there exists a rainbow solution to a b c 2 mod n except in a very specific case, which we classify.