Partitions
Time limit1sMemory limit128 MB
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 is a way of writing as a sum of positive integers listed in non-increasing order. We write a partition as a sequence with and . For example, , , and are all partitions of .
Given two distinct partitions and , let be the first position at which they differ (that is, for every and ). We say when . Because and are partitions of the same integer, such a position always exists.
This rule orders all partitions of lexicographically, from the smallest to the largest. For example, the partitions of in order are:
(1,1,1,1,1)
(2,1,1,1)
(2,2,1)
(3,1,1)
(3,2)
(4,1)
(5)
Given and a positive integer , find the -th partition (counting from ) in this ordered list of partitions of .
Input
The first line contains , the number of test cases. Each of the next lines contains two positive integers and .
Output
For each test case, output the -th partition of in lexicographic order, written as its parts separated by commas and enclosed in parentheses, for example (5,3,2,1,1). If is greater than the total number of partitions of , output Too big instead.