This page is still under construction.

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

Partitions

Time limit1sMemory limit128 MB

Summary
Given k and a, output the a-th partition of k in lexicographic order, or Too big when a exceeds the partition count.
Level

Hard8 of 10

Topics
Dynamic programming, Combinatorics, Brute force, Implementation
Solved
No attempts yet

Problem

A partition of a positive integer kk is a way of writing kk as a sum of positive integers listed in non-increasing order. We write a partition as a sequence (a1,a2,…,an)(a_1, a_2, \dots, a_n) with a1≥a2≥⋯≥an≥1a_1 \ge a_2 \ge \dots \ge a_n \ge 1 and a1+a2+⋯+an=ka_1 + a_2 + \dots + a_n = k. For example, (12)(12), (2,2,2,2,2,2)(2,2,2,2,2,2), and (5,3,2,1,1)(5,3,2,1,1) are all partitions of 1212.

Given two distinct partitions A=(a1,a2,…,an)A = (a_1, a_2, \dots, a_n) and B=(b1,b2,…,bm)B = (b_1, b_2, \dots, b_m), let tt be the first position at which they differ (that is, ai=bia_i = b_i for every i<ti < t and at≠bta_t \ne b_t). We say A>BA > B when at>bta_t > b_t. Because AA and BB are partitions of the same integer, such a position tt always exists.

This rule orders all partitions of kk lexicographically, from the smallest to the largest. For example, the partitions of 55 in order are:

(1,1,1,1,1)
(2,1,1,1)
(2,2,1)
(3,1,1)
(3,2)
(4,1)
(5)

Given kk and a positive integer aa, find the aa-th partition (counting from 11) in this ordered list of partitions of kk.

Input

The first line contains NN, the number of test cases. Each of the next NN lines contains two positive integers kk and aa.

Output

For each test case, output the aa-th partition of kk in lexicographic order, written as its parts separated by commas and enclosed in parentheses, for example (5,3,2,1,1). If aa is greater than the total number of partitions of kk, output Too big instead.

Examples2

  1. Example 1

    Input
    3
    1 1
    5 4
    5 8
    
    Expected output
    (1)
    (3,1,1)
    Too big
    
  2. Example 2

    Input
    7
    5 1
    5 2
    5 3
    5 4
    5 5
    5 6
    5 7
    
    Expected output
    (1,1,1,1,1)
    (2,1,1,1)
    (2,2,1)
    (3,1,1)
    (3,2)
    (4,1)
    (5)