使一个正整数分解为若干整数,使其各个数的乘积最大

针对一个议会人员分组的问题,需要将N名代表分成不同大小的互斥小组,确保每天每组能派出一名代表参加委员会,并且每次参会人员组合都不相同。通过分析,找到了最优的分组策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

面试碰到的一道题,这道题的原型是:

Parliament
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 12324 Accepted: 5134

Description

New convocation of The Fool Land's Parliament consists of N delegates. According to the present regulation delegates should be divided into disjoint groups of different sizes and every day each group has to send one delegate to the conciliatory committee. The composition of the conciliatory committee should be different each day. The Parliament works only while this can be accomplished.
You are to write a program that will determine how many delegates should contain each group in order for Parliament to work as long as possible.

Input

The input file contains a single integer N (5<=N<=1000 ).

Output

Write to the output file the sizes of groups that allow the Parliament to work for the maximal possible time. These sizes should be printed on a single line in ascending order and should be separated by spaces.

Sample Input

7

Sample Output

3 4

题目的大致意思是要把成员分解成若干不重合的团体,每天每个团体派一个人参加会议(可多次派出),每次会议的人应不同(整体)。

分析:

首先把一个正整数N拆成若干正整数只有有限种拆法,所以存在最大乘积。
假设N =n_1+\ldots +n_k. 并且 n_1 \times \ldots n_k是最大乘积.
  1. 显然1不会出现在其中;
  2. 如果对于某in_i \geq5,那么把n_i 拆成3+(n_i -3),我们有3(n_i -3) = 3 n_i -9>n_i,所以不存在大于等于5的因子;
  3. 如果n_i = 4, 拆成2+2乘积不变,所以不妨假设没有4;
  4. 如果有三个以上的2, 那么3\times 3 > 2\times 2\times 2,所以替换成3乘积更大
综上,选用尽量多的3,直到剩下2或者4时用2.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值