Here's an answer summarizing the comments and addressing the computational complexity.
You can't find "all the numbers $m$" since there are infinitely many, so suppose you are interested in those less than some $M$. You need to look at all the integers less than $M$, which bounds your time as $\Omega(M)$.
You can compute the greatest common divisor of $a$ and $m$ in time $O(\log (a)$. Since $a$ is fixed that's essentially a constant in your analysis, so the time is $O(M)$.
In an actual application there may be ways to bypass computing all those greatest common divisors and speed things up. You could factor $a$, then use an Eratosthenes sieve to cross off all the integers less than $M$ that share a prime divisor of $a$.