ITPEC FE Subject B October 2024 Question 4

Source exam: ITPEC FE Subject B October 2024Topic: Math & Numbers

ITPEC FE Subject B October 2024 — Question 4 of 20

Filling in blanks for a prime factorization procedure using trial division.

The program performs trial division: starting from i = 2, it repeatedly checks whether num is divisible by i. If yes, it outputs i as a factor, divides num by i, and checks whether more factors remain. If not, it increments i.

Blank A must check divisibility: num mod i = 0. When true, i is a prime factor — the program outputs i and divides num by i.

Blank B appears in two places:
1. After outputting a factor — if num > 1, more factors remain, so print the "×" separator. If num = 1, factorization is complete — no separator needed.

2. Loop condition (`while`) — continue the loop while num > 1. Once num reaches 1, all prime factors have been extracted.

Trace with input 12:

Step`i``num``num mod i`ActionOutput
12120divide → num = 6, check 6 > 1 → true
2260divide → num = 3, check 3 > 1 → true
3231not divisible → i = 3
4330divide → num = 1, check 1 > 1 → false3
51while (1 > 1) → false → exit

Final output: 2×2×3

Why not others:
- (a) A = `num < 1` — never true for positive input; no factor would ever be extracted

- (b) A = `num > 1`, B = `num mod i = 0` — A should test divisibility, not magnitude; B as a while-condition (while num mod i = 0) would exit the loop whenever i doesn't divide num, breaking the algorithm

- (d) A = `num mod i ≠ 0` — inverted logic; would divide num by i precisely when i is not a factor

Key rule: In trial division, the inner check is always "does i divide num evenly?" (mod = 0), and the outer loop continues while num > 1.

AI-generated — may contain errors

The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.