One can treat complex multiplication as polynomial multiplication, but remembering i^2 = -1. To perform polynomial multiplication, multiply each term one by one, then add them together. Hence (3+i)(1+2i) = 3x1 + 3x2i + ix1 + ix2i = 3 + 6i + i + 2 i^2 = 3 + 6 i + i + 2x(-1) = 3 + 6i + i - 2. Now collect like terms, so terms with i add together and the same with terms without i. This gives (3+i)(1+2i) = 1 + 7i. So a = 1, b = 7.