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)?

  1. A. 28
  2. B. 22
  3. C. 26
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic