A house will have maximum signal strength if the signal doesn’t have to travel through another house, that is, if we draw a straight line from the town hall to that house, the line doesn’t go through another line. Now let the coordinate of the town-hall be and the coordinate of the candidate house be , then and , the house will have maximum signal iff , here GCD represents the greatest common divisor of two numbers.
Using inclusion-exclusion and bit-masking we can calculate the number of coordinates with in and using that we can find the other coordinates.