Problem:
Score : 800 points

Problem Statement

In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed.

Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X/2)-th (rounded up to the nearest integer) lexicographically smallest one.

Constraints

1 \leq N,K \leq 3 × 10^5

N and K are integers.

Input

Input is given from Standard Input in the following format:

K N

Output

Print the (X/2)-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where X is the total number of sequences listed in FEIS.

Sample Input 1

3 2

Sample Output 1

2 1

There are 12 sequences listed in FEIS: (1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3).
The (12/2 = 6)-th lexicographically smallest one among them is (2,1).

Sample Input 2

2 4

Sample Output 2

1 2 2 2

Sample Input 3

5 14

Sample Output 3

3 3 3 3 3 3 3 3 3 3 3 3 2 2

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <iostream>
#include <vector>

using namespace std;

const long long INF = (1LL << 36);

vector<int> solve(int K, int N){
    vector<int> res;
    if(K % 2 == 0){
        res.push_back(K/2);
        for(int i=0;i<N-1;i++) res.push_back(K);
        return res;
    }
    vector<long long> block(N);
    block.back() = 1;
    for(int i=N-2;i>=0;i--){
        block[i] = K * block[i+1] + 1;
        if(block[i] >= INF) block[i] = INF + (block[i] % 2);
    }
    int offset = 0;
    res.push_back((K+1)/2);
    for(int i=1;i<N;i++){
        if(block[i]/2 <= offset){
            long long order = (K * block[i])/2 - offset;
            while(order){
                --order;
                res.push_back(1 + order/block[i]);
                order %= block[i];
                ++i;
            }
            break;
        } else {
            res.push_back((K+1)/2);
            if(block[i]%2 == 1) ++offset;
        }
    }
    return res;
}

int main(){
    int K, N;
    while(cin >> K >> N){
        auto res = solve(K, N);
        cout << res[0];
        for(int i=1;i<res.size();i++) cout << " " << res[i];
        cout << endl;
    }
}