While searching for non-isomorph subgroups of order $2002$ I just encountered something, which I want to understand. Obviously I looked for abelian subgroups first and found $2002=2^2*503$ so we have the groups $$ \mathbb{Z}/2^2\mathbb{Z} \times \mathbb{Z}/503\mathbb{Z},\mathbb{Z}/2\mathbb{Z} \times \mathbb{Z}/2\mathbb{Z} \times \mathbb{Z}/503\mathbb{Z} $$
Now I want to understand why those two are not isomorph. I know that for two groups $\mathbb{Z}/n\mathbb{Z} \times \mathbb{Z}/m\mathbb{Z} \cong\mathbb{Z}/(nm)\mathbb{Z}$ it has to hold that $\gcd(n,m)=1$. But I don't understand how we can compare Groups written as two products with groups written as three products as above, how does that work? And I think that goes in the same direction: How is it then at the same time that $$ \mathbb{Z}/4\mathbb{Z} × \mathbb{Z}/503\mathbb{Z} \cong \mathbb{Z}/2012\mathbb{Z} \ncong \mathbb{Z}/2\mathbb{Z} × \mathbb{Z}/2\mathbb{Z} × \mathbb{Z}/503\mathbb{Z} \cong \mathbb{Z}/2\mathbb{Z} × \mathbb{Z}/1006Z $$ because $\gcd (4,2012)\neq 1, \gcd (2,2)\neq 1, \gcd (503,1006)\neq 1 $. I don't understand the difference to the first comparison.
First let's note that $2^2\cdot503=2012\ne2002$.
Abelian groups of order 2002:
There is only one Abelian group of order $2002$, namely
$$\Bbb{Z}_{2002}\cong\Bbb{Z}_{2}\times\Bbb{Z}_{7}\times\Bbb{Z}_{11}\times\Bbb{Z}_{13}$$
Abelian groups of order 2012:
Since $2012=2^2\cdot503$ it might initially seem like there are four possibilities:
$$\Bbb{Z}_{2}\times\Bbb{Z}_{2}\times\Bbb{Z}_{503}$$ $$\Bbb{Z}_{4}\times\Bbb{Z}_{503}$$ $$\Bbb{Z}_{2}\times\Bbb{Z}_{1006}$$ $$\Bbb{Z}_{2012}$$
But using the fact that
$$\Bbb{Z}_n\times\Bbb{Z}_m\cong\Bbb{Z}_{nm}\quad\text{iff}\quad GCD(n,m)=1.$$
we get that
$$\Bbb{Z}_{2}\times\Bbb{Z}_{2}\times\Bbb{Z}_{503}\cong\Bbb{Z}_{2}\times\Bbb{Z}_{1006}$$
and
$$\Bbb{Z}_{4}\times\Bbb{Z}_{503}\cong\Bbb{Z}_{2012}$$
and
$$\Bbb{Z}_{2}\times\Bbb{Z}_{1006}\ncong\Bbb{Z}_{2012}$$
Hence there are exactly two non-isomorphic groups of order $2012$.