Let $G$ which is a cyclic group with $n$ elements. Find:
a) all possible subgroups
b) all elements which generate whole group.
I know that number of subgroups is the number of total divisors of $n$. Moreover if $l|(|G|=n)$ then exist exactly one subgroup $H$ such that $|H|=l$.
However I know how to do this task when I know $n$.
For example for $n=6$ we have divisors: $1,2,3,6$ so we have $4$ supgroups.
Meanwhile I have a problem when I don't know $n$:
Let $G= \left\{ e,g,g^{2},\dots ,g^{n-1} \right\}$ then we have: $$\langle e\rangle=\left\{ e \right\}$$ $$\langle g\rangle =\left\{ e,g,g^{2},\dots ,g^{n-1} \right\}$$ But I already have a problem with $\langle g^2\rangle $ because firstly I have: $\langle g^2\rangle =\left\{ e,g^{2},g^{4},\dots ,g^{n-1}\right\}$ but I don't know if $n=2k+1$ and this is whole $\langle g^2\rangle $ or $n=2k$ and $g^2$ is not a generator of any subgroups.
How can I do this task for every $n$?