ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains

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 the lcm of the first lcm with the third. The procedure below computes lcm(4, 6, 10, 15). What is printed?

Four numbers 4, 6, 10 and 15 are combined pairwise: the lcm of a and b is computed as a*b div gcd(a, b), and the lcm of three numbers is the lcm of the first lcm with the third. The procedure below computes lcm(4, 6, 10, 15). What is printed?
L = 4
for each next number x in (6, 10, 15)
    L = L * x div gcd(L, x)
end for
Print L
  1. A. 60
  2. B. 30
  3. C. 3600
  4. D. 1

Correct answer: A. 60

The lcm of 4, 6, 10 and 15 is 60. Dividing by two gives 30, multiplying all values without dividing by the gcd gives 3600, and the gcd of the four numbers is 1.

More Pseudocode and Code Tracing questions

Exams that ask this topic