Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
What is gcd(2^12 - 1, 2^8 - 1)?
- A. 15
- B. 16
- C. 17
- D. 19
Correct answer: A. 15
gcd(2^a - 1, 2^b - 1) = 2^gcd(a,b) - 1; here gcd(12, 8) = 4, so the answer is 2^4 - 1 = 15.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many integers in [2, 20] are neither divisible by 2 nor by 3?
- How many division steps (modulo operations) does Euclid's algorithm perform on the pair (252, 105) before the remainder becomes 0?
- A binary search on the sorted array 1, 2, ..., 100 looks for 37 using mid = (lo + hi) // 2 with lo = 0 and hi = 99. How many comparisons…
- How many unordered index pairs i < j in the sorted array [1, 3, 4, 6, 8, 9, 11] satisfy a[i] + a[j] = 12?
- How many distinct non-empty substrings does the string aaaa have?
- An array has only positive integers and you need the longest contiguous subarray whose sum is at most K, with n up to 10^6. Which method…