function(n)
array x of n+1 booleans, all set to true
x[0] = x[1] = false
for i in 2 : n
if x[i] = true
j = 2 * i
while j < n
x[j] = false
j += i
Details and Assumptions:
The question asks for the best upper bound to the runtime of the pseudocode, so if you think there are multiple correct answers, choose the answer which is the best upper bound among them.
Excel in math and science
Master concepts by solving fun, challenging problems.
It's hard to learn from lectures and videos
Learn more effectively through short, conceptual quizzes.
Our wiki is made for math and science
Master advanced concepts through explanations,
examples, and problems from the community.
Used and loved by 4 million people
Learn from a vibrant community of students and enthusiasts,
including olympiad champions, researchers, and professionals.
Your answer seems reasonable.
Find out if you're right!