Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
What is the smallest positive integer x such that x! (x factorial) ends with at least 1000 zeros?
- A. 4000
- B. 4005
- C. 4010
- D. 200
Correct answer: B. 4005
The number of trailing zeros of x! is Σ ⌊x / 5ᵏ⌋, which is non-decreasing in x, so binary search finds the first x that reaches N. Dividing N by 5 counts only one term of the sum.
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 substrings of "abcabcb" contain at least one each of the letters a, b and c?
- What is the length of the shortest substring of "aabcbcdbca" that contains every distinct letter appearing in the whole string at least…
- How many contiguous subarrays of [4, 2, 3, 1, 6, 5, 7, 9] satisfy max − min = (length of the subarray) − 1? Count every such subarray…
- What is the length of the longest substring of "bbaacabaacb" that contains EXACTLY two letters 'a'?
- Choose exactly 4 elements of [6, 1, 9, 4, 7, 2, 8, 5] (by position) such that no two chosen positions are adjacent. What is the maximum…
- How many permutations of 1, 2, 3, 4, 5 have exactly 3 inversions (pairs of positions i < j with p[i] > p[j])?