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- A. 60
- B. 30
- C. 3600
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- Count the integers n with 1 <= n <= 100 that are divisible by 3 or by 5, but NOT by both. The procedure below does this with a single…
- For N = 100 the procedure below counts how many times 5 divides the factorials, that is, the number of trailing zeros of 100!. The count…
- The procedure below reverses the digits of N = 120450 (trailing zeros disappear in the numeric result). What is printed? rev = 0; m = N…
- An Armstrong number of three digits equals the sum of the cubes of its digits. The procedure below counts how many three-digit numbers…
- Compute C(10, 3) modulo 7 using Pascal's rule C(n, k) = C(n-1, k-1) + C(n-1, k), reducing every entry mod 7. What is printed? build the…
- By Fermat's little theorem, for a prime p and a not divisible by p, the inverse of a is a^(p-2) mod p. The procedure below finds the…