开发者

Expressing an integer as a sum of integers with minimum variance

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜