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: Wrong Answer)

#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll pwr(ll x, ll e){
  if(e==0)
    return 1;
  ll tmp=pwr(x, e/2);
  tmp=tmp*tmp;
  if(e%2)
    tmp*=x;
  return tmp;
}
ll k, pr[300010];
ll biger(ll x, ll y){
  ll tmp=0;
//  cout<<x<<", "<<y<<endl;
  for(int i=0; i<y; ++i){
    tmp+=pr[i];
    if(tmp>x)
      return 0;
  }
//  cout<<"#"<<tmp<<endl;
  return 1;
}
  ll n;
void pre(){
  pr[0]=1;
  for(int i=1; i<=n; ++i){
    pr[i]=pr[i-1]*k;
  }
}
int main(){
  while(cin>>k>>n){
    pre();
    if(k%2==0){
      cout<<k/2<<" ";
      for(int i=1; i<n; ++i){
        printf("%lld ",k/2+1);
      }
      cout<<endl;
      continue;
    }
    ll tmp=0, tmp1;
    for(ll i=0; i<n; ++i){
      tmp1=(n-i)*k;
//      cout<<endl<<"**"<<tmp<<endl;
      if(biger(tmp,n-i-1)){
        tmp-=pr[n-i-1];
        printf("%lld ",(k+1)/2-1);
      }
      else{
        printf("%lld ",(k+1)/2);
      }
      if(tmp1%2)
        ++tmp;
    }
    cout<<endl;
  }
  return 0;
}