### maximum product of the numbers which have the sum n

I must write a program that gives the maximum product of the numbers that added are equal to n, a value entered by user. I could only come up with a a simplified version of the program, based on a supposition I made, that the biggest product is the one obtained by multiplying its basic prime factors. I'll give an example:

for n=10

biggest product possible is 2^5, 2+2+2+2+2=2*5=10

for n=11

biggest product possible is 2^4*3, 2+2+2+2+3=11 (if n is impair then the last term of the multiplication must not be 1 because 2^5*1<2^4*3)

How could I make a program that runs through all the possible products (for example, if n=5, it will test 1*1*1*1*1, 1*1*1*2, 1*1*3, etc.)

This is from a test for college admission and I don't know if my simplified solution would get max points, or any points at all.
Last edited on
Maybe i am wrong because I have not understood the assignment but in my opinion the biggest product for n=10 is 25 ( 5 * 5 ).
Last edited on
Stick to the KISS rule.

Anyway, I believe what you're looking for is something along the lines of:

`n = (k/2)^2`
Last edited on
In your example for n=10, you have 2^5 which is actually supposed to be 32.

2*2*2*2*2 = 32

Assuming that we're only talking about integers here, and not floats, then I think your supposition is correct. After all, multiplying something by 4 is the same as multiplying it by 2*2.

So your program should only run through the prime numbers. And I think that you can skip any testing with 1, unless n is a number between 1 and 3.

As for how you're going to create a program that goes through all the possible products, I have no idea. I'm only a beginner, but I think that will take a lot of calculations and not be very efficient.

I think you need to find someone good at math that can give you some more rules on what would create the highest product.

EDIT:
After thinking about it some more, I think that you should make sure you didn't misunderstand the problem. If it's asking for the maximum product of any two numbers that added are equal to n, then that is much easier than asking the maximum product of an indeterminate amount of numbers that added are equal to n. In the first case, then just use ResidentBiscuit's formula.
Last edited on
Topic archived. No new replies allowed.