面试碰到的一道题,这道题的原型是:
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.
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
题目的大致意思是要把成员分解成若干不重合的团体,每天每个团体派一个人参加会议(可多次派出),每次会议的人应不同(整体)。
分析:
首先把一个正整数
拆成若干正整数只有有限种拆法,所以存在最大乘积。
假设
并且
是最大乘积.
,直到剩下2或者4时用
.
假设
- 显然1不会出现在其中;
- 如果对于某
有
,那么把
拆成
,我们有
,所以不存在大于等于5的因子;
- 如果
, 拆成
乘积不变,所以不妨假设没有4;
- 如果有三个以上的
, 那么
,所以替换成3乘积更大