Skip to content
Discussion options

You must be logged in to vote

We need to determine the number of operations required to reduce either of two given non-negative integers to zero by repeatedly subtracting the smaller number from the larger one. The operations continue until one of the numbers becomes zero.

Approach

  1. Simulation with Optimization: Instead of simulating each subtraction step one by one (which could be inefficient for large numbers), we use integer division to calculate how many operations can be performed in one go.
  2. Efficient Subtraction: For each step, if num1 is greater than or equal to num2, we calculate how many times num2 can be subtracted from num1 using integer division. This count is added to the total operations, and num1 is upd…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Nov 9, 2025
Maintainer Author

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Nov 9, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants