Let $n$ and $k$ be integers with $1\le k < n$. Form a graph $G$ whose vertices are the integers $0,1,2,...,n-1$. We have an edge joining the vertices $a$ and $b$ provided $$a-b \equiv \pm k \pmod n\;.$$ We were given the example if $n=20$ and $k=6$, then vertex $2$ would be adjacent to vertices $8$ and $16$. I need to find a formula involving $n$ and $k$ for the number of connected components of $G$.
I tried creating other examples, with $k=1$ and $n=2$, with $k=2$ and $n=20$, etc, and the pattern that I seemed to find was that the number of components was equal to $k$. But I know that this cannot be the correct solution since $n$ is not involved in this formula, so I also tried $n \bmod k$ as the formula, which seemed to work. Is $n \bmod k$ a legitimate formula for the number of connected components of $G$?