Prime Factorization

Dear All,
I'm writing a program to factorize an integer into 2 factors only. for example, the prime factorization for 24 is: 2,2,2,3, but what I want the output to be only 4 and 6. another example, 42: 2,3,7 but my what I want the output to be is 6 and 7. where 6 comes from the multiplications of the two smallest factors: 2X3 and I do not want the results to be 2 and 21 where 21 comes from the multiplications of 3 and 7. in other words , the output must indicates find the smallest two integers for a list of factors of an integer.


another example 60: 2,2,3,5

the output I want it is 2x3 and 2x5 = 6,10 = 16
and not 2x2 and 3X5 = 4,15 = 19
because 16 is less than 19 and this is what I want actually.

Thanks in advance
one more clarification that I forgot to say it:

one may say 60 comes from : 2,2,3,5

so 2x2x3 = 12 , so 12 and 5, but it still 12 + 5 = 17 which is greater than 16.

so this output is not valid for my problem.


Thank you very much for your kind help :)
You'll have to prime factorize it completely, making sure your list of factors is sorted.

Then just grab from the ends until you've used all factors.

60: {2,2,3,5} --> {2,3},2×5 --> {},2×3,2×5 --> {},6,10

The only thing to watch is an odd-length list: grab the smaller values first instead of from the ends.

12: {2,2,3} --> {3},2×2 --> {},3,2×2 --> {},3,4

Hope this helps.
Topic archived. No new replies allowed.