MOHIBTREE - Keyur and Mohib Tree
This Time Keyur (Singal) has been challenged by his friend Nishant (Vaju). As Keyur's programming skills are very poor, he asked you to help him. So as a great programmer you have to help Keyur. The challenge is as follows:
Keyur has given a binary tree Mohib-tree. Every Mohib-tree has the following properties:
- Every Mohib-tree contains a root node that stores a positive integer greater than or equal to 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.
The following are valid Mohib-Trees:
6 6 / \ / \ 2 4 3 3 / \ 2 2
Input
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
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 Mohib-trees with root N.
Constraints
0 < T <= 20
2 <= N <= 1014
Sample
Input: 3 2 6 31 Output: Case #1: 0 Case #2: 2 Case #3: 0
hide comments
Sushovan Sen:
2022-06-24 09:50:17
General suggestion for anyone getting WA for o/p format. Easiest way to deal with it is to copy-paste answer from here to your code and make necessary changes. |
|
Waseem Ahmed:
2021-10-06 21:35:03
Interesting problem |
|
TUSHAR SINGHAL:
2016-04-06 11:41:20
wtf ... changed a variable from int to long long .. and submission verdict changed from tle to AC .... don't know why .. :p
|
|
adi_tri:
2016-02-28 17:19:59
o/p format caused me 3 WA..!! otherwise easy one..!! Last edit: 2016-02-28 17:36:31 |
|
Soma:
2016-02-16 14:15:08
@author : can u tell me why am i getting WA? submission id := 16226690
|
|
try2catch:
2016-02-05 05:43:30
easy! brute force. java takes 0.5 secs |
|
varun bumb:
2016-02-03 15:32:53
EASY but nice! Last edit: 2016-02-03 15:33:11 |
|
ivanilos:
2016-02-03 02:11:49
@Lets_Code
|
|
Lets_Code:
2016-02-02 20:23:18
Please make the output format clear...is there any space between "colon" and "answer"?? Bcz in output format, u havnt given any space there but in testcase output, there is a space between "colon" and "0". |
Added by: | MoHib85 |
Date: | 2016-01-22 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU JS-MONKEY |