Square (AOJ 0507) by mzsrkn10
Contest: 3575    RunID: 2376059    Status: Accepted    Date: Sat Jun 17 14:59:06 JST 2017


#include<bits/stdc++.h>
using namespace std;

void solve(int left, int right, vector<int> v){
    if(right == 0){
        for(int i=0;i<v.size();++i){
            cout << v[i];
            if(i+1 == v.size())cout << endl;
            else cout << " ";
        }
    }else{
        for(int i=right;i>0;--i){
            if(i <= left){
                v.push_back(i);
                solve(i, right - i, v);
                v.pop_back();
            }
        }
    }
}

int main(){
    int n;
    while(cin >> n, n != 0){
        for(int i=n;i>0;--i){
            vector<int> v;
            v.push_back(i);
            solve(i, n - i, v);
            v.pop_back();
        }
    }

    return 0;
}