This page is still under construction.

Parts of this page are still being built. What you see may change.

Gwen's Gift

Time limit1sMemory limit512 MB

Summary
Count and construct the kth lexicographic sequence of length n-1 with entries in [1, n-1] where no contiguous block sums to a multiple of n.
Level

Medium7 of 10

Topics
Combinatorics, Math, Dynamic programming, Greedy
Solved
No attempts yet

Problem

Gwen loves most numbers. In fact, she loves every number that is not a multiple of nn (she really hates the number nn). For her friends' birthdays this year, Gwen has decided to draw each of them a sequence of n−1n-1 flowers. Each of the flowers will contain between 11 and n−1n-1 flower petals (inclusive). Because of her hatred of multiples of nn, the total number of petals in any non-empty contiguous subsequence of flowers cannot be a multiple of nn. For example, if n=5n = 5, then the top two paintings are valid, while the bottom painting is not valid since the second, third and fourth flowers have a total of 1010 petals. (The top two images are Sample Input 33 and 44.)

Gwen wants her paintings to be unique, so no two paintings will have the same sequence of flowers. To keep track of this, Gwen recorded each painting as a sequence of n−1n-1 numbers specifying the number of petals in each flower from left to right. She has written down all valid sequences of length n−1n-1 in lexicographical order. A sequence a_1,a_2,…,a_n−1a\_1,a\_2,\dots, a\_{n-1} is lexicographically smaller than b_1,b_2,…,b_n−1b\_1, b\_2, \dots, b\_{n-1} if there exists an index kk such that a_i=b_ia\_i = b\_i for i<ki < k and a_k<b_ka\_k < b\_k.

What is the kkth sequence on Gwen's list?

Input

The input consists of a single line containing two integers nn (2≤n≤1 0002 \leq n \leq 1\,000), which is Gwen's hated number, and kk (1≤k≤10181 \leq k \leq 10^{18}), which is the index of the valid sequence in question if all valid sequences were ordered lexicographically. It is guaranteed that there exist at least kk valid sequences for this value of nn.

Output

Display the kkth sequence on Gwen's list.

Examples4

  1. Example 1

    Input
    4 3
    
    Expected output
    2 1 2
    
  2. Example 2

    Input
    2 1
    
    Expected output
    1
    
  3. Example 3

    Input
    5 22
    
    Expected output
    4 3 4 2
    
  4. Example 4

    Input
    5 16
    
    Expected output
    3 3 3 3