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 Rust (1.15.1) (judge verdict: Accepted)

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn naive(k: usize, n: usize) {
    let mut cnts = vec![0 as usize; n + 1];
    cnts[0] = 1;
    for i in 0..n {
        cnts[i + 1] = cnts[i] * k + 1;
        // println!("{}", cnts[i + 1]);
    }
    let mut rest = cnts[n] / 2;
    let mut ans = vec![];
    let mut pos = n - 1;
    while rest > 0 {
        // println!("{} {} {}", rest, pos, cnts[pos]);
        rest -= 1;
        let skip = rest / cnts[pos];
        ans.push(skip);
        rest -= cnts[pos] * skip;
        if pos == 0 {
            break;
        }
        pos -= 1;
    }
    for i in 0..ans.len() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", ans[i] + 1);
    }
    println!("");
}

fn minus(seq: &mut Vec<usize>, k: usize, n: usize) {
    for i in (0..n).rev() {
        if seq[i] == 0 {
            continue;
        }
        seq[i] -= 1;
        if seq[i] == 0 {
            return;
        }
        for j in i + 1..n {
            seq[j] = k;
        }
        break;
    }
}
fn solve(k: usize, n: usize) {
    let mut ans = vec![];
    if k % 2 == 0 {
        ans.push(k / 2);
        for _i in 0..n - 1 {
            ans.push(k);
        }
    } else {
        ans.push(k / 2 + 1);
        for _i in 0..n - 1 {
            ans.push(k / 2 + 1);
        }
        let offset = n / 2;
        for _i in 0..offset {
            minus(&mut ans, k, n);
        }
    }
    for i in 0..ans.len() {
        if ans[i] == 0 {
            break;
        }
        if i != 0 {
            print!(" ");
        }
        print!("{}", ans[i]);
    }
    println!("");
}

fn main() {
    let k: usize = read();
    let n: usize = read();
    if k == 1 {
        naive(k, n)
    } else {
        solve(k, n);
    }
}