ProgrammingHardTCS NQT · Accenture
The least common multiple of the integers 1 through 10 is computed by folding lcm(a, b) = a b div gcd(a, b) from L = 1. The procedure below prints the result. What is printed?
The least common multiple of the integers 1 through 10 is computed by folding lcm(a, b) = a * b div gcd(a, b) from L = 1. The procedure below prints the result. What is printed?
L = 1
for i = 1 to 10
L = L * i div gcd(L, i)
end for
Print L- A. 2520
- B. 3628800
- C. 840
- D. 55
Correct answer: A. 2520
Dividing by the gcd at each step gives 2520, which is the lcm of 1 to 10. The product 10! = 3628800 ignores the shared factors, stopping at 8 gives 840, and the sum 55 is an unrelated quantity.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- Count the three-digit numbers (100 to 999) in which every digit is odd. The procedure below uses a loop over the numbers and checks each…
- Count the pairs (i, j) with 1 <= i <= j <= 10 for which the product i j is a perfect square. The procedure below does this with two nested…
- The procedure below finds the largest prime less than 100 by testing each candidate from 99 down to 2 for divisibility by 2 up to its…
- The procedure below sums the integers from 1 to 100 that are NOT divisible by 2 and NOT divisible by 3. What is printed? total = 0 for n =…
- Count the numbers n with 1 <= n <= 100 such that both n and n + 2 are prime (twin primes, lower member n). The procedure below checks…
- 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…