Data Structures & AlgorithmsHardGATE CS · ICPC regional
How many integers in the range 1 to 100 are coprime to 30 (that is, gcd(x, 30) = 1)?
- A. 28
- B. 22
- C. 26
- D. 32
Correct answer: C. 26
Since 30 = 2 * 3 * 5, a number is coprime to 30 exactly when it is divisible by none of 2, 3 and 5. Inclusion-exclusion over multiples of these primes counts them directly.
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 pairs of distinct array positions i < j in [1, 2, 3, 4, 5, 6, 9] have a[i] a[j] divisible by 6?
- What is the total number of distinct values obtained by summing two different elements of [1, 2, 3, 4] (order does not matter)?
- How many substrings of length 2 in the string abcabcab occur at least twice in the string (possibly overlapping)?
- For the array [1, 2, 3, 4, 6, 12], how many index pairs i < j have a[j] divisible by a[i]?
- Minimum number of elements to delete from [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] so the remaining sequence is non-decreasing (equal neighbours…
- How many index pairs i < j satisfy a[i] > 2 a[j] for a = [5, 1, 3, 9, 2, 8, 4]?