Question 179
Given an integer $n \gt 1$ and an integer $a$ that is coprime with $n$. There is a country consisting of $n$ islands $D_1, D_2, \dots, D_n$. For any two different islands $D_i$ and $D_j$, there is a one-way ferry from $D_i$ to $D_j$ if and only if $ij \equiv ia \pmod{n}$. A tourist hopes to visit as many islands as possible. He can first fly to any island he chooses to start the tour, and afterwards can only use the one-way ferry to tour freely between islands in this country. Find the maximum possible number of different islands that the tourist can visit.