ProgrammingHardTCS NQT · Accenture
Let N = 360. The procedure below counts the divisors of N by testing every i from 1 to N. What is printed?
Let N = 360. The procedure below counts the divisors of N by testing every i from 1 to N. What is printed?
count = 0
for i = 1 to N
if N mod i == 0 then count = count + 1
end for
Print count- A. 23
- B. 12
- C. 24
- D. 1170
Correct answer: C. 24
360 = 2^3 * 3^2 * 5 has (3+1)(2+1)(1+1) = 24 divisors. Excluding N itself gives 23, testing only up to the square root counts just half the pairs, and summing the divisors gives 1170.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- A number's digit sum is computed by the procedure below for N = 98765. What is printed? s = 0; m = N while m > 0 s = s + (m mod 10) m = m…
- The procedure below uses the sieve of Eratosthenes on the range 2 to 50, marking composites starting from ii. The inner marking statement…
- Compute 3^13 mod 7 with the binary method below (a = 3, e = 13, m = 7). What is printed? result = 1; base = a mod m; e = 13 while e > 0 if…
- Let phi(n) be the number of integers i with 1 <= i <= n that share no common factor with n except 1. The procedure below computes phi(36)…
- Starting from n = 27, the Collatz step is applied: if n is even, n becomes n/2, otherwise n becomes 3n + 1. The procedure below counts the…
- Four numbers 4, 6, 10 and 15 are combined pairwise: the lcm of a and b is computed as ab div gcd(a, b), and the lcm of three numbers is…