LLCA - Largest Labeled Common Ancestor
Given a labeled complete k-ary tree, find the largest labeled common ancestor of two given nodes. In a complete k-ary tree, the node in the tree is labeled sequentially from the left most child to right most child, level by level. Largest labeled common ancestor of A and B is defined as the largest labeled node in the tree which has A and B as descendants. A node is a descendant of itself.
Be careful with your finger, the source limit is 256 bytes.
Input
The first line of input contains an integer T (1 <= T <= 100) the number of cases. Each cases contains three integers K, A and B (2 <= K <= 100; 1 <= A, B <= 2,000,000,000).
Output
For each test case, output in a line the largest labeled common ancestor node.
Example
Input: 4 3 42 7 2 2 6 2 1 105 4 10 13 Output: 2 1 1 3
Whitespace Explanation
If there no input in any line, then the output for that line is a blank line :)) Sorry for inconvenience. >:)
hide comments
Rishav Goyal:
2014-08-06 12:42:23
@problemSetter, how hard it is to correct input files. Its just really annoying.!
|
|
numerix:
2011-09-25 10:09:10
Justin: You are right, the input data is broken. There seem to be more or less than 3 values in at least one line and/or empty lines in between.
|
|
hendrik:
2011-09-25 10:09:10
Justin: I tried to start a discussion about the quality of the input files in the forum. No one really cared. You have to live with the fact that some problemsetters dont do a good job or perhaps dont know anything else than scanf. Last edit: 2011-06-07 23:32:30 |
|
skeeve:
2011-09-25 10:09:10
Are there extra blank lines at the beginning of the input? Something like that is going on (though I got around it). I hate it when problems do stupid things like that. Is it so hard to make good, simple input files? I hate wasting time on things like this. |
|
numerix:
2011-09-25 10:09:10
The source limit isn't too strict, but the time limit is for some interpreted languages, because of long startup time of the interpreter (e.g. Pike, Java). So, please set time limit to a higher value. Thanks.
|
|
Hendra Jaya:
2011-09-25 10:09:10
I spent more time minimizing the source code than constructing the algorithm.
|
|
যোবায়ের:
2011-09-25 10:09:10
why? @Andri |
|
Muhammad Andri Ihsannudin:
2011-09-25 10:09:10
i think the problem submitter has a problem. :| |
|
Prahesa Kusuma Setia:
2011-09-25 10:09:10
NICE PROBLEM GAN! xD |
Added by: | Lukmanul Hakim |
Date: | 2010-11-08 |
Time limit: | 1s |
Source limit: | 256B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | ACM-ICPC Indonesia National Contest 2010, Problem B |