Parliament

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分割成不同的, 數字,這些數字要相對少

#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long lint;
int a[1005];
int ans;
int aa(int a){
    return a*(a+1)/2-1;
}
void solve(int n){
    for(int i=2; ;++i){
        if(aa(i+1)>n){
            int s=aa(i);
            int mid=(n-s)/(i-1);
            int k=(n-s)%(i-1);
            int j;
            for(j=2;j<=i-k;++j){
                a[ans++]=j+mid;
            }
            for(j=i-k+1;j<=i;++j){
                a[ans++]=j+mid+1;
            }
            return ;
        }
    }
}
int main()
{
    int n;
    while(cin>>n){
        memset(a,0,sizeof(a));
        ans=0;
        solve(n);
        for(int i=0;i<ans;++i){
            cout<<a[i];
            if(i==ans-1)
                cout<<endl;
            else
                cout<<" ";
        }
    }
    return 0;
}

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章