Solution (source code)

= Solution

<Lagrange's theorem for finite groups> states that if $H\leq G$ and $G$ is finite, then
$$
|G|=[G:H]|H|,
$$
so $|H|$ divides $|G|$. Indeed, the left <cosets> of $H$ partition $G$, and multiplication by a coset representative is a bijection from $H$ to each coset.

Applying the theorem to the <cyclic subgroup> $\langle g\rangle$ gives
$$
\operatorname{ord}(g)=|\langle g\rangle|\mid |G|.
$$

In $C_3\times C_9$, an element has order dividing three exactly when its first coordinate is arbitrary and its second belongs to the unique subgroup of order three. There are $3\cdot3=9$ such elements, and after removing the identity the answer is $\boxed8$.