# Finite Encyclopedia of Integer Sequences（找规律）

### 6617: Finite Encyclopedia of Integer Sequences

[提交] [状态] [讨论版] [命题人:admin]

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≤N,K≤3×105
N and K are integers.

Input is given from Standard Input in the following format:
K N

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.

3 2

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).

1、k为偶数，序列为：k/2、k、k、k.......，共n个数。

2、k为奇数，序列为：(k+1)/2、(k+1)/2、(k+1)/2、(k+1)/2.......再往前推2/n个。

3、如果不知道为什么while里要这么写的，可以写个n=4，k=3的情况，不用全写完。看一看两个序列之间怎么变化的就知道了。或者在while里输出一下这个序列就ok。

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=3e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
int a[MAX];
int main()
{
int n,k,indx;
scanf("%d%d",&k,&n);
indx=n;
if(k%2==0)
{
a[1]=k/2;
for(int i=2;i<=n;i++)
a[i]=k;
}

else
{
int temp=n/2;
for(int i=1;i<=n;i++)
a[i]=(k+1)/2;

while(temp--)
{
if(a[indx]==1)
a[indx--]--;

else
{
a[indx]--;
while(indx<n)
a[++indx]=k;
}
}
}

for(int i=1;i<=indx-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[indx]);
return 0;
}