Data Structures & AlgorithmsHardGATE CS · TCS NQT
What is the smallest positive integer k such that k! is divisible by 2^10 = 1024?
- A. 10
- B. 12
- C. 20
- D. 7
Correct answer: B. 12
Legendre: v₂(k!) = ⌊k/2⌋ + ⌊k/4⌋ + ⌊k/8⌋ + ...; at k = 11 it is 5 + 2 + 1 = 8, at k = 12 it reaches 6 + 3 + 1 = 10. Counting only ⌊k/2⌋ gives 20, assuming v₂ = k gives 10, and 7 is the first k with k! ≥ 1024, not divisible by it.
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
- What is the length of the longest contiguous subarray of [2, 3, 1, 2, 4, 3] whose sum is exactly 7?
- The array [5, 3, 8, 6, 2] must be split into exactly 2 contiguous groups, minimising the largest group sum. What is that minimum?
- Evaluate "2 3 # 4 #" where the binary operator # on operands a and b (in postfix order) returns a b + 1.
- What is the minimum number of operations needed to reduce 191 to 0, where each operation subtracts any single power of two that is at most…
- What is the sum of all integers from 1 to 100 inclusive that are divisible by neither 3 nor 7?
- How many windows of length 3 in [1, 2, 1, 2, 3, 3, 1] contain exactly two distinct values?