#P6241. Jernej's Tower Game
Jernej's Tower Game
Jernej's Tower Game
Jernej is bored at night and invented a game. He builds a tower using number cards. Initially, he places a card with the number \(1\). In each move, he writes a new number on a new card and places it on top of the tower. The new number must be equal to the sum of a contiguous segment of cards already in the tower. Formally, if the tower currently has \(n\) numbers \(a_1,a_2,\dots,a_n\), then he may select any segment \([l,u]\) with \(1\le l\le u\le n\) and write the number \[ \sum_{i=l}^{u}a_i \] on a new card that is then placed at the top of the tower.
Jernej wants to create \(T\) towers (i.e. for multiple queries), each ending with a desired top card value given in the input. Your task is to help him determine the minimum number of moves required to form a tower whose top card equals the given target, as well as output one valid sequence of moves. Each move is represented by two integers \(l\) and \(u\), indicating the indices of the contiguous segment chosen in that move. Note that if the target is \(1\), no moves are needed since the tower already begins with \(1\).
inputFormat
The first line contains an integer \(T\) (\(1\le T\le 10\)), the number of queries. Each of the next \(T\) lines contains one integer \(target\) (\(1\le target\le 1000\)), representing the desired top card value of a tower.
outputFormat
For each query, output the following:
- In the first line, output an integer \(k\) denoting the minimum number of moves required.
- If \(k>0\), then output \(k\) subsequent lines. Each of these lines contains two integers \(l\) and \(u\) (with \(1\le l\le u\le\) current tower length in that move), indicating the indices of the contiguous segment selected to form the new card.
If the target is \(1\), simply output a line with 0
.
sample
1
1
0
</p>