spoj#MOHIBTREE. Keyur and Mohib Tree
Keyur and Mohib Tree
This Time Keyur(Singal) has been challenged by his friend Nishant(Vaju).As keyur's programming skills are very poor so He asked you to help him, So As a Great programmer you have to help keyur.The challenge is as follow:
Keyur has given a binary tree Mohib-tree. Every Mohib-tree has the following properties-
1. Every Mohib-tree contains a root node that stores a positive integer greater than or equal to 2.
2. Every node of an Mohib-tree is either a leaf node (has no children) or has exactly 2 children which are Mohib-trees as well.
The sum of values of children nodes is always equal to the value of the parent node.
Value of at least one of the children nodes divides the parent value.
The height of the tree is defined as the number of edges from the root to the deepest leaf.
Following is a valid Mohib-Tree:
6 6
/ \ / \
2 4 3 3
/ \
2 2
Input Format :
The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with one line with one integer N, which represents the value of the root node.
Output Format:
For each test case, output one line containing "Case #x:", where x is the test case number (starting from 1). Then, for every value N in the test case, output the maximum possible height of all R-trees with root N.
Constraints:
0 < T <= 20
2 <= N <= 1014
Input:
3
2
6
31
Output:
Case #1: 0 Case #2: 2 Case #3: 0