I will post a sketch of my solution:
Lemma: Any subgroup of $\mathbb{Z}^n$ can be generated by at most $n$ elements.
Proof: We define the dimension of a group as the smallest $k$ such that there exists $k$ vectors $v_1,\cdots,v_k$ such that each element in the group can be written as $\sum_{j=1}^k c_jv_j$ where $c_j\in \mathbb{Q}$. We will show that if $G$ is a subgroup of $\mathbb{Z}^n$ and has dimension $k$, then $G$ can be generated by $k$ elements.
First we prove that $G$ is finitely generated; add vectors $v_{k+1}, \cdots, v_n$ in $\mathbb{Z}^n$ to form a basis of $\mathbb{Q}^n$ (over $\mathbb{Q}$) as necessary. We consider the parallelopied with vertices $\sum _{i=1}^k\epsilon_i v_i$ where $\epsilon_j \in \{0,1\}$ for all $j$ and by induction on $n$, we can show the measure (in the real analysis sense; can be seen as a notion for length/area/volume) of the parallelopied is $$\text{det} \begin{bmatrix}
v_1 & \cdots & v_n
\end{bmatrix}$$
Which is finite. Call this quantity $M$
Now consider tiling $\Omega=[0, T]^n$ with these parallelopieds where $T \to \infty$. We can show that there are $T^n / M + O(T^{n-1})$ parllelopieds with nonempty intersection, where the $O(T^{n-1})$ comes from errors in the boundaries. Any parallelopied that doesn't come intersect with the boundary of $\Omega$ contains exactly one point in $span_{\mathbb{Z}}(v_1,\cdots,v_n)$ (in fact each point in each possible "residue" of $\mathbb{Z}^n / span_{\mathbb{Z}}(v_1,\cdots,v_n)$), and there are $O(T^{n-1})$ points outside. Therefore, $\mathbb{Z}^n / span_{\mathbb{Z}}(v_1,\cdots,v_n)$ is finite and has size $M$. This readily implies $G$ is finitely generated.
Pick $k$ vectors $v_1,\cdots,v_k$ in $G$ that are linearly independent, then for any $k+1$th vector $v_{k+1}$ not in $span(v_1,\cdots,v_k)$, there exist integers $c_1,\cdots,c_{k+1}$ with $\gcd(c_1,\cdots,c_{k+1})=1$ such that $\sum c_jv_j = 0$. Using Euclidean algorithm we can play around with $v_j$'s and $c_j$'s such that one $c_j$ becomes 1; delete the corresponding $v_j$ and the group got larger. This process is finite (see above) so the lemma is proven.
Now go back to the problem. Consider a map from $\omega$ (the unit circle) to $\mathbb{R} / \mathbb{Z}$ by $\exp(2\pi i t) \to t+\mathbb{Z}$. Since elements have finite order, we can see that the image is contained in $\mathbb{Q} / \mathbb{Z}$. We can use this to turn multiplication into addition.
The denominators of the elements in the group are bounded, say they are all divisors of $K$. Then this subgroup $G$ can be seen as a finite subgroup of $(\mathbb{Z}/K\mathbb{Z})^n$. The group $G'$ (which is a subgroup of $\mathbb{Z}^n$) that contains all $(K\mathbb{Z})^n$-cosets of $G$. By lemma, $G'$ is finitely generated, say by $v_1,\cdots,v_t$. Then $G$ is also generated by $v_1,\cdots,v_t$. Let $m=ord(v_t)$, then $G$ is the direct product of $span(v_1,\cdots,v_{t-1})$ and $(\mathbb{Z}/m\mathbb{Z})$
It remains to show that $span(v_1,\cdots,v_{t-1})$ is isomorphic to a subgroup of $(\mathbb{Z}/k\mathbb{Z})^{t-1}$, which is isomorphic to a subgroup of $(\frac 1k\mathbb{Z}/\mathbb{Z})^{t-1} \subset (\mathbb{Q}/\mathbb{Z})^{t-1} $
Best Answer
As written, the algorithm is... poorly defined. I guess that you meant:
Let $i=1$, and $G_0= \emptyset$.
That being said, you are asking why it is enough to restrict attention to powers of $a_i$ that have a power of $p$ as exponent. The answer is that $a_i^p$ and $a_i^{pq}$ whenever $q$ does not divide $p$ generate the same subgroup. In fact, $G$ is a $p$-group and all elements have order $p^m$ for some $m \in \mathbb{N}$, so $a_i^{pq}$ has to have the same order as $a_i^p$. So this seemingly weaker hypothesis is actually equivalent to the standard requirement.