We know the following fact from gorup theory: If $G$ is a group of prime order then it has no nontrivial subgroups.
Lets try to prove the converse statement: If $G$ has no nontrivial subgroups, show that $G$ must be finite of prime order.
Proof: Suppose by contradiction: If $G$ has no nontrivial subgroups $\Rightarrow$ $G$ is infiinite or $|G|\neq p$.
The case when $G$ is infinite we can rule out using that topic.
Suppose that $|G|=n$ where $n$ is composite $\Rightarrow$ $n=pm$ where $p$ - prime and $m\geqslant 2$. Let $a\in G$ such $a\neq e$ then $a^{pm}=e$.
If $a^p\neq e$ then considering the cyclic group of G, namely $H=\left \langle a^p\right \rangle$ $\Rightarrow$ $1<|H|\leqslant m<pm$ this is a contradiciton.
If $a^p=e$ then we know that $a\neq e$ and considering the cyclic subgroup of $G$, namely $H=\left \langle a\right \rangle$ $\Rightarrow$ $1<|H|\leqslant p<pm$
So we get two contradiction and it follows that $G$ is finite and its order is prime.
P.S. I think that my post is not duplicate because my solution somewhat is different from given duplicates. And this solution was created by me and it was important for me to understand is it correct or not.