ProgrammingHardCAT · MBA placement
The number of ordered pairs (x, y) of positive integers with x y = 36 is counted by the procedure below. What is printed?
The number of ordered pairs (x, y) of positive integers with x * y = 36 is counted by the procedure below. What is printed?
count = 0
for x = 1 to 36
if 36 mod x == 0 then count = count + 1
end for
Print count- A. 8
- B. 3
- C. 10
- D. 9
Correct answer: D. 9
The ordered pairs correspond to the 9 divisors of 36, one pair per divisor. Leaving out x = 36 loses a pair, counting only one half of the pairs gives a different count, and the range starting at zero adds a pair that is not positive.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The Josephus game: n = 7 people stand in a circle numbered 1 to 7, and every third person is removed (counting continues around the…
- The procedure below sums the prime factors of N = 360 counted with multiplicity (2 counted three times, and so on) by trial division. What…
- A product of ten consecutive numbers 1 x 2 x ... x 10 is computed. The procedure below counts how many of the numbers 1 to 10 are…
- Smallest n such that n! has at least 5 trailing zeros is searched for by the procedure below, where z(n) is the number of factors 5 in n!…
- A number N = 1296 is reduced by the procedure below, which divides by the smallest prime factor each time it can and keeps a count of the…
- The procedure below counts the numbers from 1 to 1000 whose digit sum is exactly 5. It uses digit-sum by repeated division. What is…