This method will work, but in a competition situation, you'll have to be very good at bashing. A much simpler way to do this problem is to consider (b, 37) as a rotation of 60 degrees of (a, 11). This method is much easier and requires almost no bash. You can either use trigonometric sum identities, rotations on the complex plane, or rotation mapping of matrices; they are all equivalent.