Skip to content
Activities · Activity 4.1

Q.What sequence of steps will you follow to compute the LCM of two numbers?

Punjab PsebTextbookSubjective· 3mImportance★★★★★est
6% · 2/36 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

The LCM (least common multiple) is the smallest number divisible by both inputs — so generate multiples of the larger number and stop at the first one the smaller number also divides; or, faster, use LCM = (a × b) / GCD(a, b).

The idea. Framing "find the LCM" as a sequence of steps is exactly what an algorithm is. Checking multiples of the larger number (rather than counting 1, 2, 3 …) is a small but real optimisation: every candidate is already a multiple of one number, so we only test divisibility by the other.

Algorithm (sequence of steps):

Step 1: INPUT a, b
Step 2: SET multiple = max(a, b)
Step 3: IF multiple MOD a == 0 AND multiple MOD b == 0 THEN
            LCM = multiple; go to Step 5
Step 4: multiple = multiple + max(a, b); go to Step 3
Step 5: PRINT LCM

Python implementation:

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
step = max(a, b)
multiple = step
while multiple % a != 0 or multiple % b != 0:
    multiple = multiple + step
print("LCM =", multiple)

Trace for a = 4, b = 6:

multiple testeddivisible by 4?divisible by 6?verdict
6NoYeskeep going
12YesYesLCM found

Expected output:

Enter first number: 4
Enter second number: 6
LCM = 12
``` …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.