Given an odd number $\,n,\,$ I'm trying to find a way to map natural numbers $\,k\,$ onto a set of $\large{\text{odd}}$ numbers $\,j\,$ where $\,GCD(n,j)=1.\quad$ In the table below, I have had to skip $\,k$-values $\,(3,5,6,9,10,12,15)\,$ for the composite number $\,15=3\cdot5.$
\begin{array}{c|c|c|c|c|} n & k& GCD(n,k) & j \text{ need} & j-k\text{ diff}\\ \hline 15& 1 & 1 & 1 & 0 \\ \hline 15& 2 & 1 & 2 & 0\\ \hline 15& 3 & 3 & 4 & 1\\ \hline 15& 4 & 1 & 7 & 3 \\ \hline 15& 5 & 5 & 8 & 3 \\ \hline 15& 6 & 3 & 11 & 5 \\ \hline 15& 7 & 1 & 13 & 6 \\ \hline 15& 8 & 1 & 14 & 6 \\ \hline 15& 9 & 3 & 16 & 7 \\ \hline \end{array}
If $\,n\,$ were prime we could use a simple funcion like $j=k+\bigg\lfloor\frac{(k-1)}{(n-1)}\bigg\rfloor\,$ because the floor component need only skip single non-coprime values of $\,k\,$ in favor of co-prime values of $\,j.$ The problem with composite $\,n$-values is that there must be a look-ahead of sorts because there can be more than one non-coprime $\,(n,k)\,$ pair in a sequence. I want to map $$\{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,\cdots\}$$ onto $$\{1,2,4,7,8,11,13,14,16,17,19,22,23,26,28,29,\cdots\}$$ I have tried such as the following where $\,p_1, p_2,\cdots\,$ are prime factors of $\,n\,$ but it has no ability to look ahead.
\begin{align*} j=k+\bigg\lfloor\frac{(k)}{(p_1)}\bigg\rfloor +\bigg\lfloor\frac{(k)}{(p_2)}\bigg\rfloor+\cdots\ \end{align*}
It appears that there can be as many sequential non-coprime $\,(n,k)\,$ pairs as there are prime factors of $\,n.\,$ How do I look ahead to tell how mny additional number skips are needed? A program could do it but how do I put that logic into a function?