🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Number Theory for Coding: all 10 questions

Quiz: Number Theory for Coding · Question 5 of 10

What does this print? (code)

What does this print?

N = 30
is_p = [True] * (N + 1)
is_p[0] = is_p[1] = False
for p in range(2, 6):
    if is_p[p]:
        for k in range(p * p, N + 1, p):
            is_p[k] = False
print(sum(is_p))
  1. A.9
  2. B.10
  3. C.11
  4. D.15
Answer & explanation

Correct answer: 10

The primes up to 30 are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29.

Can you get the rest right without peeking?

Take the timed Quiz: Number Theory for Coding quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →