Finite Group Primary Decomposition Theorem the theorem goes as follows, for every finite abelian group $G$ of order $mn$ where $m$ and $n$ are relatively prime, there exists subgroups $A,B \leq G$ such that $G = A \oplus B$ where $|A| = m$ and $|B| = n$.
I chose $A = \left\{ g \in G \:{:}\: mg = 0 \right\}$ and $B = \left\{ g \in G \:{:}\: ng = 0 \right\}$, then I managed to show that $G = A \oplus B$. 
The only remaining task is to show that $|A| = m$ and $|B| = n$. The solution says first suppose $|A| = a$ and $|B| = b$ so that $|G| = mn = ab$ and let the prime $p$ divide $a$, then there exists $h \in A$ such that $ph = 0$, but since $mh =0$, $p \mid m$ and it implies $m = a$.
I don't understand the last point, let's say $|G| = p_1^2p_2^2p_3p_4p_5$ of distinct primes and let $|A_1| = p_1^2p_3$, $|B_1| = p_2^2p_4p_5$ and $|A_2| = p_1^2p_3p_5$, $|B_2| = p_2^2p_4$, then surely for every prime dividing $|A_1|$, it also divides $|A_2|$, but $p_1^2p_3 \neq p_1^2p_3p_5$.
Any clarification would be greatly appreciated.
 A: Suppose $\gcd(a,n)>1$. Then there exists a prime factor $p$ of $\gcd(a,n)$. Then $p|a$, and you have shown that $p|m$. Thus $p|\gcd(n,m)$, a contradiction. Hence $\gcd(a,n)=1$, so $nn'\equiv1\pmod a$ for some $n'\in\mathbb Z$. Thus $m\equiv mnn'\equiv0\pmod a$, so $a|m$. Similarly $b|n$. Writing $m=aa'$ and $n=bb'$ where $a',b'\geq1$ are integers, we have $ab=mn=(ab)(a'b')$, whence $a'b'=1$. Thus $a'=b'=1$, so $m=a$ and $n=b$.
A: After spending hours, I came up with a solution, which is simpler to understand.
We know for every prime $p$, $p \mid a$ implies $p \mid m$ and similarly $p \mid b$ implies $p \mid n$. Let's suppose $a \neq m$, then we have two cases (1) $a$ and $b$ are coprime (2) $a$ and $b$ are not coprime.
(1) Since $a \neq m$, we have a prime $p_1$ such that $p_1 \mid m$ but $p_1 \nmid a$, then $p_1 \mid b$ and $p_1 \mid n$, which is contradictory because $(m,n) = 1$, so $a = m$ and $b = n$.
(2) Since $a \neq m$, we have a prime $p_1$ such that $p_1 \mid a,m$ but also $p_1 \mid s$, then $p_1 \mid n$ and we have a contradiction, so $a = m$ and $b = n$. 
