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>
#define INF 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int k,n;
ll sum=0;
int ans[300005];

ll mod_pow(ll x,ll n){
	ll ans=1;
	while(n>0LL){
		if(n&1)ans=ans*x;
		x=x*x;
		n>>=1;
	}
	return ans;
}

ll calc(ll rest,ll val){
	ll ans=0;
	ll now=1;
	if(val==1)return rest;
	for(int i=0;i<rest;i++){
		ans+=now*val;
		ans=min(ans,INF);
		now*=val;
		now=min(now,INF);
		if(ans==INF)return INF;
	}
	return ans;
}

ll C(int v,int i){
	if(v==0)return 0;
	ll ans=1;
	ll now=v-1;
	if(now==0)return 1;
	if(k==1)return (ll)ans+now*(n-i);
	ans+=(ll)now*(1LL-mod_pow(k,n-i))/(1-k);
	/*
	for(int j=i;j<n;j++){
		ans+=now;
		now*=k;
	}
	*/
	return ans;
}

int main(void){
	scanf("%d%d",&k,&n);
	int size=0;
	if(k%2==0){
		size=n;
		ans[0]=k/2;
		for(int j=1;j<size;j++){
			ans[j]=k;
		}
	}else{
		ll diff=0;
		size=1;
		for(int i=0;i<n;i++){
			if(calc(n-i,k)<=1000000LL){
				ll rest=calc(n-i,k);
				if(rest<diff){
					i--;
					diff--;
				}
				ll zure=(rest-diff)/2;
				if((rest-diff)%2LL==1)zure++;
				while(zure>0LL && i<n){
					int l=0,r=k+1;
					while(l+1<r){
						int mid=(l+r)/2;
						if(C(mid,i)<=zure){
							l=mid;
						}else{
							r=mid;
						}
					}
					zure-=C(l,i);
					if(l==0)break;
					ans[i]=l;
					size++;
					i++;
				}
				break;
			}else{
				ans[i]=(k+1)/2;
				size++;
				diff++;
			}
		}
	}
	bool flag=false;
	for(int i=0;i<n;i++){
		if(ans[i]==0)break;
		if(flag)printf(" ");
		printf("%d",ans[i]);
		flag=true;
	}
	printf("\n");
	return 0;
}