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 <bits/stdc++.h>
using namespace std;
using lint = long long int;
lint K, N;
constexpr lint INF = 100000000000;

template <typename T>
T power(T x, T n, T inf)
{
    T ans = 1;
    bool infflag = false;
    while (n>0)
    {
        n--;
        ans *= x;
        if (ans > inf) return inf;
        // if (n & 1)
        // {
        //     if (infflag) return inf;
        //     ans = ans * x;
        // }
        // x = x * x;
        // if (x >= inf || x < 0) infflag = true;
        // n >>= 1;
    }
    return ans;
}

void saiki(lint n, lint res)
{
    int tmp = K/2+1;
    while (res < -(power(K, n, INF)-1)/(K-1))
    {
        tmp++;
        res += 2 * (power(K, n, INF)-1)/(K-1);
    }
    while (res >= (power(K, n, INF)-1)/(K-1))
    {
        tmp--;
        res -= 2 * (power(K, n, INF)-1)/(K-1);
    }
    if (tmp == 0) return;
    cout << tmp << " ";
    if (n>1) saiki(n-1, res+1);
}


int main()
{
    cin >> K >> N;
    if (K == 1)
    {
        for (int i=0; i<(N+1)/2; i++) cout << 1 << " ";
        return 0;
    }
    if (K%2==0)
    {
        cout << K/2 << " ";
        for (int i=0; i<N-1; i++) cout << K << " ";
        return 0;
    }
    saiki(N, 0);
    return 0;
}