Construct a Coin Set

시간 제한1초메모리 제한1024 MB

요약
각 N에 대해 1원부터 N-1원까지는 그리디가 최적해를 주지만 N원에서는 그렇지 않은 동전 집합을 만들거나, 불가능하면 -1을 출력한다.
난이도

보통10점 중 7점

유형
그리디, 수학, 정수론, 완전 탐색
정답자
아직 제출이 없습니다

문제

The change-making problem is the problem of finding the minimum number of coins that add up to the change to be returned after purchasing items at a shop. A coin set refers to a collection of coin values available for making the change. The greedy algorithm for the change-making problem repeatedly selects the largest coin value among the coin set that does not exceed the remaining amount of change. This process continues until the total amount of change is made.

An optimal solution refers to a solution that uses the fewest number of coins. However, the greedy algorithm does not always guarantee an optimal solution. Under certain conditions, the greedy algorithm may give a non-optimal solution.

Given a positive integer NN, your task is to find a coin set for which the greedy algorithm returns an optimal solution for all amounts from 11 won to (N−1)(N-1) won, but not for NN won. Notice that the coin whose value is 11 is always in the coin set.

입력

The first line of input contains the number of test cases TT. Each of the next TT lines of input contains a single integer NN.

출력

For each test case,

If it is impossible to construct a coin set satisfying the conditions given in the problem, print −1-1.

If it is possible to construct a coin set, print the size of the coin set KK in the first line. In the next line, print the coin values a_1,a_2,…,a_Ka\_{1},a\_{2},\ldots ,a\_{K}, separated by spaces in increasing order. The size of the coin set does not have to be a minimum.

제한

  • 1≤T≤1,0001\le T\le 1\\, 000
  • 1≤N≤1091\le N\le 10^{9}
  • 1≤K≤301\le K\le 30
  • 1=a_1\<a_2<⋯\<a_K≤1091=a\_{1}\<a\_{2}<\cdots \<a\_{K}\le 10^{9}

예제1

  1. 예제 1

    입력
    2
    6
    3
    
    예상 출력
    3
    1 3 4
    -1