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.
You can base an algorithm on the following theorem:
Borrowing one of Steven Gregory's examples, let's show that $P(120)=P(450)$ by showing first that $P(120)\subseteq P(450)$ and then that $P(450)\subseteq P(120)$.
For the first inclusion, we note that $(120,450)=30\gt1$, hence
$$P(120)\subseteq P(450)\iff P(4)\subseteq P(450)$$
We next see that $(4,450)=2\gt1$, hence
$$P(4)\subseteq P(450)\iff P(2)\subseteq P(450)$$
Finally, $(2,450)=2\gt$, hence
$$P(2)\subseteq P(450)\iff P(1)\subseteq P(450)$$
and the theorem says the last statement, $P(1)\subseteq P(450)$, is true.
For the reverse inclusion, similar considerations give
$$\begin{align} P(450)\subseteq P(120)&\iff P(15)\subseteq P(120)\quad\text{since }(450,120)=30\gt1\\ &\iff P(1)\subseteq P(120)\quad\text{since }(15,120)=15\gt1\\ \end{align}$$
Just to give one more example, let's show that $P(420)\not=P(450)$:
$$\begin{align} P(420)\subseteq P(450)&\iff P(14)\subseteq P(450)\quad\text{since }(420,450)=30\gt1\\ &\iff P(7)\subseteq P(450)\quad\text{since }(14,450)=2\gt1\\ \end{align}$$
but $(7,450)=1$ with $7\not=1$, so the theorem says $P(7)\not\subseteq P(450)$, which implies $P(420)\not\subseteq P(450)$, which means the two certainly aren't equal.
Remark: It's worth noting that the algorithm described here will take something like $10$ iterations to show $P(1024)\subseteq P(2)$, which seems excruciatingly slow, but in the grand scheme of things, that's only about three times the number of digits in the number $m$, which is not so bad. In particular, the algorithm never requires you to explicitly find any of the prime factors of $m$ or $n$; it will, for example, run happily on a pair of million-digit numbers each of which is a product of powers of some unknown set of thousand-digit primes.