ITPEC FE Subject B April 2025 Question 2

Source exam: ITPEC FE Subject B April 2025Topic: Math & Numbers

ITPEC FE Subject B April 2025 — Question 2 of 20

Perfect number check — fill in the condition and accumulator for summing divisors.

A perfect number equals the sum of its proper divisors (all positive divisors excluding itself). The program loops k from 1 to n ÷ 2 and needs to:
- A (condition): check if k divides nn mod k = 0

- B (accumulate): add the divisor itself → sum ← sum + k

Trace with n = 28:
- k=1: 28 mod 1 = 0 → sum = 0+1 = 1

- k=2: 28 mod 2 = 0 → sum = 1+2 = 3

- k=3: 28 mod 3 ≠ 0 → skip

- k=4: 28 mod 4 = 0 → sum = 3+4 = 7

- k=7: 28 mod 7 = 0 → sum = 7+7 = 14

- k=14: 28 mod 14 = 0 → sum = 14+14 = 28

- sum = 28 = n → return true ✓

Why not others:
- (a) n mod k ≠ 0 selects non-divisors; sum + 1 counts instead of summing

- (b) n mod k ≠ 0 selects non-divisors (wrong filter)

- (c) n mod k = 0 is correct, but sum + 1 counts divisors instead of summing them

Key rule: to sum divisors, check n mod k = 0 (divisibility) and accumulate k itself, not 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.