Given two positive integers $m$ and $n$ such that $1<m<n$, what is an efficient way to check if the prime factors of $m$ and $n$ are exactly the same, i.e, if $\mathcal{P}_m=\mathcal{P}_n$, where $\mathcal{P}_k$ denotes the set consisting of all the prime factors of the number $k$?
I have a guess, but don't know how to prove. If we set $a_1=n/m$, then if $a_1>1$ and if $\text{gcd}\,(a_1,m)=1$, then $m$ and $n$ don't have the same prime factors. Otherwise, and here's my guess, if $m>a_1>1$ and $\text{gcd}\,(a_1,m)\neq a_1$ or if $a_1>m$ and $\text{gcd}\,(a_1,m)\neq m$ then $m$ and $n$ don't have the same prime factors. Otherwise, if $m>a_1>1$ and $\text{gdc}\,(a_1,m)=a_1$, then $m$ and $n$ have the same primes factors and if $a_1>m$ and $\text{gdc}\,(a_1,m)=m$ we repeat the process with $a_2=a_1/m$. And if for some $r$, $a_r=1$, then $m$ and $n$ have the same prime factors.
In addition to the fact that I can't show if my process if correct, it seems to me that it is too complicated. So, if there is other (less complicated) algorithm, please show me.