Let us define the Laughter sequence as a sequence of strings only containing either the character "H" or "A". This sequence is defined recursively as Lo = H L₁ = A Li Li-2 Li-1, for i > 1 (Note: S₁ S₂ means we concatenate S₁ and S₂.) The first few strings in the Laughter sequence are H. A. HA, AHA. HAAHA. AHAHAAHA. Given i and k, determine whether the kth character in L, is an H or an A. Input Format Input consists of one test case. Each test case consists of one line with two space separated integers i and k denoting the index of the string in the Laughter sequence, and the index of the character to be checked. k is a 0-based index. Constraints 0 ≤ i ≤ 105

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

Need help in solving the problem explained in the screenshot in python. Need the time complexity to be a minimum as possible, so using Binary Search would be the best approach.

The code

def solve(n,k):
  # solve problem here. Return correct answer

n, k = list(map(int,input().rstrip().split(" ")))
print(solve(n,k))

 

Output Format
Output consists of one line containing "H" (without the quotes), if the kth character in L is an H, or "A" (also
without quotes), if the kth character in L₂ is an A.
Sample Input 0
3 1
Sample Output 0
H
Sample Input 1
4 3
Sample Output 1
H
Sample Input 2
10 4
Sample Output 2
A
Transcribed Image Text:Output Format Output consists of one line containing "H" (without the quotes), if the kth character in L is an H, or "A" (also without quotes), if the kth character in L₂ is an A. Sample Input 0 3 1 Sample Output 0 H Sample Input 1 4 3 Sample Output 1 H Sample Input 2 10 4 Sample Output 2 A
Let us define the Laughter sequence as a sequence of strings only containing either the character "H" or "A".
This sequence is defined recursively as
Lo = H
L₁ = A
Li Li-2 · Li-1, for i > 1
=
(Note: S₁ S₂ means we concatenate S₁ and S₂.)
The first few strings in the Laughter sequence are H, A, HA, AHA, HAAHA, AHAHAAHA.
Given i and k, determine whether the kth character in L is an H or an A.
Input Format
Input consists of one test case. Each test case consists of one line with two space separated integersi and k,
denoting the index of the string in the Laughter sequence, and the index of the character to be checked. k is a
0-based index.
Constraints
0 ≤ i ≤ 105
0 ≤ k < min(10¹8, |Li|)
f
in
Contest ends in 2 days 8 hours 16
minutes 3 seconds
Submissions: 54
Max Score: 1
Rate This Challenge:
你你你你你
More
Transcribed Image Text:Let us define the Laughter sequence as a sequence of strings only containing either the character "H" or "A". This sequence is defined recursively as Lo = H L₁ = A Li Li-2 · Li-1, for i > 1 = (Note: S₁ S₂ means we concatenate S₁ and S₂.) The first few strings in the Laughter sequence are H, A, HA, AHA, HAAHA, AHAHAAHA. Given i and k, determine whether the kth character in L is an H or an A. Input Format Input consists of one test case. Each test case consists of one line with two space separated integersi and k, denoting the index of the string in the Laughter sequence, and the index of the character to be checked. k is a 0-based index. Constraints 0 ≤ i ≤ 105 0 ≤ k < min(10¹8, |Li|) f in Contest ends in 2 days 8 hours 16 minutes 3 seconds Submissions: 54 Max Score: 1 Rate This Challenge: 你你你你你 More
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning