Create 50 different numbers that add up to a total number

JoshT

New member
Joined
Sep 23, 2022
Messages
1
Hello,

I'm working on a programming project of my own and I'm trying to find the best way to formulate 50 different numbers which add up to a total number. The numbers can't be the same, so I can't simply take the total number and divide by 50. The total number will change each time, but I need all 50 numbers to be different and add up to the total number, whatever it might be. Also, I need the numbers after the decimal to be ignored. I need only whole numbers (the program I'm designing ignores the numbers after the decimal anyway and doesn't round up or down).

So far, I have worked it out this way, but I'm wondering if there's an easier way:
Let's say the total number is 1,058,587

1. So to create the first number I take 1,058,587 divided by let's say 75 which = 14114.493, but because my program can't handle decimals and only uses whole numbers, the first number would be 14,114
2. Then I take 1,058,587 minus 14,114 = 1,044,473
3. Then to create the second number, I take 1,044,473 and divide by let's say 89 which = 11735 (without the decimals) and that becomes my second number

I repeat steps 1-3 over and over dividing by different numbers to get 50 different numbers which add up to the total.
For the 50th number, it's okay if it's the remainder.

Is there an easier way and what would the formula look like?

Thanks for any help anyone can provide! :)
 
If the integers are allowed to be negative and positive, then there are infinite solutions to this problem. However, l'll assume that all integers must be positive.

1. So to create the first number I take 1,058,587 divided by let's say 75 which = 14114.493, but because my program can't handle decimals and only uses whole numbers, the first number would be 14,114
2. Then I take 1,058,587 minus 14,114 = 1,044,473
3. Then to create the second number, I take 1,044,473 and divide by let's say 89 which = 11735 (without the decimals) and that becomes my second number
Please explain where you obtained 75 and 89 (highlighted above). Are these randomly generated numbers?

--

There is a simpler way to do this (IMO). Can you think of three numbers that add up to 6? Call them [imath]n_1,n_2 \text{ and } n_3[/imath]. Now, if you needed four integers that add up to, say, 234 then this would be a possible answer...
[math]n_1+n_2+n_3+x=234[/math]...and can you find x using very simple algebra? Since you're programming then I assume that you might know some basic algebra (even though you posted this under "Arithmetic")

This idea can be extended to 50 integers (from the example with 4 above).
 
Top