Given two non-negative integers, A and B , you can perform these four operations:
1. A+=B
2. B+=A
3. A+=A
4. B+=B
If A = 2 0 2 0 , B = 2 0 2 1 , is it possible to make A and B equal after finite operations?
Bonus: Given any non-negative integer A , B , if it is possible to make them equal, try to find a general strategy or algorithm to make them equal in your discussion. If there isn’t a way to make them equal, try to explain why.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
There's actually a flaw of your approach. If doing 3rd operation 2021 times, then A will become A*2^2021 (Since you are multiplying A by two 2021 times)
Log in to reply
Just realised I had misread this - I'd thought you'd posted the incorrect solution! Sorry about that. I've deleted the report now.
I seem to have now found a correct solution. However, Brilliant isn't giving me the option to post a solution. I'm not sure if it only offers the option if I've submitted a correct answer, which I now can't do having submitted an incorrect answer.
Log in to reply
You can post the solution in the reply section first:)
Log in to reply
@Alice Smith – Algorithm
Let Z A and Z B be the greatest power of 2 to divide A and B respectively.
Trying it out
Given the initial values A = 2 0 2 0 , B = 2 0 2 1 , the algorithm halts at the 36th iteration, with A = B = 6 7 1 0 8 8 6 4 .
Why it works
Let A 0 , B 0 be the initial values of A and B respectively. Let A n , B n be successive values.
Let A n ′ = g cd ( A n , B n ) A n and B n ′ = g cd ( A n , B n ) B n for arbitrary n .
Then the possibilities are:
Obviously, when operation 3 or 4 has been picked, A n + 1 ′ + B n + 1 ′ < A n ′ + B n ′ .
When operation 1 has been picked, A n + 1 ′ will be even, thus operation 4 will be picked next, giving A n + 2 ′ = 2 A n + B n < A n (since A n > B n ). On the other hand, B n + 2 ′ = B n ′ . Thus in this scenario, A n + 2 ′ + B n + 2 ′ < A n ′ + B n ′ .
The same argument applies when operation 2 has been picked.
These show that, if you take out the temporary increases from operations 1 and 2, A n ′ + B n ′ becomes a strictly decreasing sequence of positive integers. Since the minimum possible value occurs when A n ′ = B n ′ = 1 , it must eventually reach this point.
Do you mean lcm(A,B)?
Also, as Alice said, A+=A results in doubling.
Depicting all this by 2x2 integer matrices applied to the vector (A, B), I arrived at constraints on the solution matrix (a, b; c, d):
• determinant must be a power of 2
• aA + bB = cA + dB
Together, this seems to be impossible because A/B*2^n can never be integer.
I got the answer wrong but still don't know why.
My 2c: wlog assume gcd(A,B)=1. Then for any integer m there are integer a,b which solves aA+bB=m (extended Euclidean algorithm). a-B,b+A is also a solution and the determinant of (a, b; a-B, b+A) is also m which we could choose to be a power of 2. But I don’t know if there is a composition of the 4 2x2 matrices that yield any such solution matrix. I don’t know how to characterize the “composition space” (?), an aspect of linear algebra that eludes me.
I’m pretty sure this can be solved for any A,B and this can be proved via a simple algorithm.
Alice, a hint please!
Aha, see “binary Euclid’s algorithm”. A sort-of backwards version of that solves 2020,2021 in 35 steps! Hint: start each step by finding which of A,B, or both have the lowest 1-bit. A proof that the algorithm always terminates would be welcome.
You can make any two non negative numbers equal by using
This operation one time only
A+=B
B+=A
As the addition is commutative
After the first operation, value of A has already changed. The question is specifically related to Computer Science, not Algebra.
It's simple Add A, B no. of times and add B, A no. of times.
A×B=AB=B×A
A+=A........B no. of times
B+=B.........A no. of times
Find lcm or if one or both are prime then multiple both that'll be the way
Problem Loading...
Note Loading...
Set Loading...
Do 3rd operation 2021 times ( = 2 0 2 0 × 2 0 2 1 ) and 4th operation 2020 times ( = 2 0 2 1 × 2 0 2 0 )
In general, do 3rd operation ( A g c d ( A , B ) ) times and 4th operation ( B g c d ( A , B ) ) times