#C4704. Replicating Tree Simulation
Replicating Tree Simulation
Replicating Tree Simulation
This problem simulates the growth of a replicating tree. You are given three integers initial_value, levels, and threshold. Starting with a single node with value initial_value, the tree grows level by level. In each level, every node v from the previous level generates up to two child nodes with values \(2v\) and \(2v+1\) respectively. However, a generated node is only added if its value does not exceed the given threshold. If at any level no new node can be added (i.e. all possible generated values exceed the threshold), the growth stops even if the specified number of levels has not been reached.
Note: If the initial_value itself exceeds the threshold, the tree will only consist of the root node.
inputFormat
The input is read from standard input (stdin) and consists of three space-separated integers: initial_value, levels, and threshold.
For example:
1 3 50
outputFormat
Output the tree level by level to standard output (stdout). Each level should be printed on a new line and the node values on the same level should be separated by a single space.
For example, the output for the input 1 3 50
should be:
1 2 3 4 5 6 7## sample
1 3 50
1
2 3
4 5 6 7
</p>