DCEPC504 - The Indian Connection
Rajesh Kuthrapali has a weird family structure. Every male member gives birth to a male child first and then a female child whereas every female member gives birth to a female child first and then to a male child. Rajesh analyses this pattern and wants to know what will be the Kth child in his Nth generation. Help him.
Note:
- Every member has exactly 2 children.
- The generation starts with a male member (Rajesh).
- In the figure given below:
M ------------ 1st generation / \ / \ / \ M F ------- 2nd generation / \ / \ M F F M | 3rd child of 3rd generation
Input
First line specifies T, the number of test cases.
Next T lines each gives 2 numbers, N and K.
Output
Output 1 line for each test case giving the gender of the Kth child in in Nth generation.
Print “Male” for male “Female” for female (quotes only for clarification).
Constraints
1 <= T <=100
1 <= N <=10000
1 <= K <= min(10^15, 2^(n-1))
Example
Input: 4 1 1 2 1 2 2 4 5 Output: Male Male Female Female
hide comments
lt:
2016-11-29 09:25:10
Simple recursion! :)
|
|
poda_venna:
2016-08-30 18:51:38
Mapppppppps :p AC in one go :P |
|
venture_walk:
2016-07-26 15:22:55
took me long enough |
|
nonushikhar:
2016-07-17 16:50:15
easy
|
|
Subhendu Sethi:
2016-06-07 19:39:10
O(log k) solution. Pretty obvious. Last edit: 2016-06-07 19:39:56 |
|
vijay kumar paliwal:
2016-06-02 07:58:57
No need to use n :)
|
|
sarvesh_19:
2016-01-22 20:08:09
long long int and recursion works :').
|
|
minhthai:
2016-01-10 17:11:10
no need to use BigInteger, remember the trick you used in BIT ? ^_^ |
|
SUBHAJIT GORAI:
2015-12-17 10:30:17
try to handle the overflow ....after some time it seems obvious ... |
|
Dushyant Singh:
2015-10-22 20:53:36
Why did people use log() ? Is there a formula? And is minimum complexity O(N) ? |
Added by: | dce coders |
Date: | 2012-04-18 |
Time limit: | 1.726s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | ASM32-GCC MAWK BC C-CLANG C NCSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JAVA JS-MONKEY JULIA KTLN NIM NODEJS OBJC OBJC-CLANG OCT PICO PROLOG PYPY PYPY3 PY_NBC R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET |
Resource: | Own Problem |