Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
How many non-empty subsets of [4, 6, 9, 10, 15] (chosen by position) have a greatest common divisor equal to 1?
- A. 17
- B. 20
- C. 15
- D. 31
Correct answer: A. 17
Enumerate subsets (or count with Möbius inversion over divisors): a subset's gcd is the greatest common divisor of its members, and most subsets of these values share a factor. Counting all non-empty subsets ignores the gcd condition.
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, 0, -1, 4, -2, 5, -1] whose product is strictly positive?
- Let P[0] = 0 and P[k] be the XOR of the first k elements of [3, 5, 6, 3, 1, 5, 2]. How many pairs of indices (i < j) among 0..7 have P[i]…
- In how many ways can the binary string "0110100110" be cut into one or more contiguous segments so that every segment contains equally…
- Among all arrangements reachable from [4, 2, 1, 3] by swapping ONE pair of adjacent elements (or by doing nothing), what is the minimum…
- What is the minimum number of single-character flips needed to make "1101001011" alternate (no two adjacent characters equal)?
- What is the maximum sum of a contiguous subarray of [3, -2, 7, 1, -5, 4, 8, -1, 2] whose length is between 2 and 4 inclusive?