Find pairs of numbers with a constant difference that have the same number of prime factors

number theoryprime factorizationprime numbers

I need to find pairs of numbers A and B such that A-B=N for some constant N say 129. The restriction for A and B are that both numbers should have p number of prime factors each and no prime factor must occur twice in the same number. For instance, p could be 5.

I did write a program to do this iteratively starting from 1 and 130(129+1). However, for huge numbers, the time taken is just too long to be feasible. Is there a better approach for this?

As an example, consider the following-
A could be 25806 and B could be 25935. Here, A will have 2 3 11 17 23 as it's factors and B will have 3 5 7 13 19 as it's factors. No factor repeats itself in the same number and both numbers have 5 factors each

Best Answer

Partial answer.

Let's look at the first case, when $p=1$. Then you are looking at the difference $a - b = N$ of primes.

If $N$ is odd then the prime $b$ must be even, so $b=2$. Then there is a unique solution for every $N$ which is $2$ less than a prime, and no solution otherwise.

If $N$ is even then the simplest case $N=2$ is unsolved, because it asks for pairs of twin primes. We don't know whether there are infinitely many, let alone how to find them.

The general problem is much much harder.

You can always start with two sets of primes, multiply each set together and subtract to find $N$ (as in your example), but starting from $N$ and asking for sets of primes is well beyond what's known.