In general, there are a huge number of possible values for $g^{ab}$, depending on what $g$ is.
However, in this case, whoever set up this problem took care to radically reduce the number of possibilities.
Here's how you would attack this problem:
In practice, these special cases don't come up that often, in this case, it does.
- Step 3: once we have the set of possible solutions to each of the subproblems, we can use the Chinese Remainder Theorem to join them together to come up with the set of solutions to the original problem.
Now, normally, each subproblem comes up with a large number of potential solutions, and so the combinatorics of step 3 comes up with a truly huge number of solutions.
However, in this case, it turns out to be only two solutions to the overall problem (and, as luck would have it, you really don't need the CRT to join those solutions in step 3; there's a simpler way to compute them).