Congruence has solutions iff Let p ∈ N be and odd prime. Show that for a, b ∈ N, p does not divide b, the congruence xa ≡ b mod p has solutions if and only if b(p−1)/hcf(a,p−1) ≡ 1 mod p.
This is what I was given as a solution:
Let g be a primitive root mod p. Writing $x ≡ g^k$ mod p and $b ≡ g^l$ mod p,
the given congruence has solutions if and only if $ak ≡ l$ mod p−1 has solutions
$$⇔ hcf(a, p−1)|l,$$ which is equivalent to $$(p − 1) |(l(p−1)/hcf(a,p−1))$$ ⇔ 1 ≡ gl(p−1)/hcf(a,p−1)
≡ b(p−1)/hcf(a,p−1) mod p.
My confusion is about the very last transition, (p − 1) |(l(p−1)/hcf(a,p−1)) ⇔ 1 ≡ gl(p−1)/hcf(a,p−1). Apologies for the formatting, but if someone can explain this step to me in more detail I would really appreciate it!

Since $\frac{l(p−1)}{hcf(a,p−1)}$ is divisible by p-1 then $g^{p-1}≡1$ so $g^{n*(p-1)}≡1$, for any n integer number (basically g to the power of any multiple of p-1 is congruent to 1 since all you are doing is multipling $g^{p-1}$ by itself and $g^{p-1}≡1$). Since $\frac{l(p-1)}{hcf(a,p-1)}$ is a multiple of p-1 then $g^{\frac{l(p−1)}{hcf(a,p−1)}}≡1$.
On the other hand, if $1 ≡ g^{\frac{l(p−1)}{hcf(a,p−1)}}$ since g is a primitive root then $\frac{l(p−1)}{hcf(a,p−1)}$ has to be multiple of $p-1$ so $\frac{l(p−1)}{hcf(a,p−1)}$ is divisible by p-1.
