Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2017/imperative-programming-resit/2/c/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2017 Imperative programming (resit) 2 c Solution by
Codex 0 2026-10-31
Before testing candidate , every earlier integer has been printed exactly when it belongs to the spectrum, and every positive satisfies . During the inner loop that exclusion remains true: an excluded candidate is passed over only after checking its square.
At termination of the inner loop, , so is the least positive possible witness. If its square is already at least , every larger witness is too large as well; otherwise it satisfies both required inequalities and is printed. Advancing preserves the earlier-witness exclusion because the new lower bound only increases. These loop invariants establish both completeness and absence of extra outputs.
New to topics? Read the docs here!