#P9736. Multiplication Using Limited Additions
Multiplication Using Limited Additions
Multiplication Using Limited Additions
In this problem, you are given four variables:
- A, with initial value \(x\)
- B, with initial value \(y\)
- C, with initial value \(0\)
- D, with initial value \(1\)
You are allowed to perform the following operation at most \(100\) times:
Operation: Select any two variables, add their values, and store the sum in one of these variables.
Your task is to use the above operation no more than \(100\) times to make at least one variable equal to \(x \times y\) (i.e. the product of \(x\) and \(y\)).
Hint: A straightforward approach is to use repeated additions, e.g., initialize C to \(0\) and add \(A\) to \(C\) a total of \(y\) times, assuming \(y \le 100\).
inputFormat
The first and only line of input contains two space-separated integers (x) and (y), representing the initial values for variables A and B respectively. It is guaranteed that (y) is such that the multiplication can be achieved with at most 100 operations.
outputFormat
Output a single integer, which is the product (x \times y).
sample
3 5
15