ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains

The procedure below counts the odd divisors of 1000 by testing every d from 1 to 1000. What is printed?

The procedure below counts the odd divisors of 1000 by testing every d from 1 to 1000. What is printed?
count = 0
for d = 1 to 1000
    if 1000 mod d == 0 and d is odd then count = count + 1
end for
Print count
  1. A. 16
  2. B. 12
  3. C. 4
  4. D. 3

Correct answer: C. 4

1000 = 2^3 x 5^3, so its odd divisors are 1, 5, 25 and 125, which is 4. Counting all divisors gives 16, counting the even divisors gives 12, and skipping 1 gives 3.

More Pseudocode and Code Tracing questions

Exams that ask this topic