Computation of discrete logarithm
As far as we know there is no efficient way to do that.  Such a way would constitute a break of the DSA scheme, and no break of the DSA is known.  In particular, DSA is believed to be secure, so it is believed that no efficient algorithm for this exists.

If you only want to do it for small numbers, you can just use brute force and try all possible values of $x$.  Or, you can solve

$$a^x \equiv b \pmod p.$$

Then any solution to that equation will be a solution to your equation as well. More generally, you can pick any constant $c$ of your choice such that $0 \le c &lt; (p-b)/q$ and solve

$$a^x \equiv b + cq \pmod p;$$

if you can't find a solution for a particular value of $c$, try another one until you can.  This won't be efficient once $p,q$ get large.