I want to know how I can express an integer as a sum of integers with minimum variance. For ex : 21 can be expressed as 6+6+6+3 or 6+5+5+5 or 18+1+1+1 or ..... But the set (6,5,5,5) has the minimum variance. I want to program in android which can do this, given an integer and 开发者_运维百科the number of elements in the set.
try just dividing by the numbers in the set (21/4 = 5) and then adding the reminder to the numbers in the set
For example, take 23.
- Divide 23/4 = 5
- take the reminder 23%4 = 3
- add one to each number of the set, until the reminder is 0.
- result = 6,6,6,5
精彩评论