There is a well-known proof for the probability of two integers being coprime. This question has been asked on this website before. The solution is given by the following infinite product: $$\prod_{p \text{ prime}} \left(1-\frac{1}{p^2}\right).$$ However, there's an aspect of this formula that I don't quite understand. Let's examine the chain of multiplications: $$\left(1-\frac{1}{2^2}\right)\left(1-\frac{1}{3^2}\right)\left(1-\frac{1}{5^2}\right)\left(1-\frac{1}{7^2}\right)\cdots$$ I interpret the term $\left(1-\frac{1}{2^2}\right)$ as the probability that two numbers are not both even, or in other words, that they are not both divisible by 2. So we are excluding pairs divisible by 2, 4, 6, 8, and so on.
Similarly, the second term $\left(1-\frac{1}{3^2}\right)$ follows the same logic but for the prime 3. We are excluding pairs divisible by 3, 6, 9, 12, and so on.
My confusion arises from numbers like 6 (=$2\times3$), which have multiple prime factors. It seems we are counting numbers with more than two prime factors multiple times, but counting prime numbers and their powers (like $2^5$) only once. Why isn't this an issue in the final result?