how can this problem as real world problem. why any one wants to reduce his work
to achieved something which he already done.
Can anyone please tell me some examples of 3 moves please??
x=1 y=7
first we add 7 to x hence it becomes 8 now.then we subtract 8 from x now x becomes 0 and then again we add 7 to x which becomes 7. so a=7 and b=8.
When X<Y it will take 1 operation when difference is odd, 2 when difference is even but not divisible by 4 else 3,
cananyone explain this?
x=4 y=0 , means that in how many minimum steps you would take to go from 4 (x) to 0 (y).
Thanks bro
but bro why it can not be happened he has already cleaned his lab and now he is at x=4
which is current .
what i mean he is already done minimum steps to achieved y
No we are not assuming that its already done.
Problem is to go from x to y in minimum steps.
Now you understood reason for 3 moves ?
Yes, for every X and Y, where Y>X, and (Y-X) is even and divisible by 4, we will get 3 operations.
For eg: X=4, Y=20
now d=(Y-X)=16 which is even and divisible by 4.
Since, odd + odd=even, we can consider a=17.
4+17+17=38.
Now we can subtract any even number to convert 38 to 20,since, even-even=even.
b=18 does our work. So b=18.
Ergo, a=17,b=18, and it took us 3 operations(minimum).
Where it is written in the problem?
Study the test cases once you will get what i am saying!
yes bro thanks for writing this.
what i was assuming that problem is real world that y is target and x r process
so we should choose optimal ans
and one thing did agree with this
y=0 mean there r no such thing in lab to clean irrespective whatever is x it does not matter so ans should be 0
You are missing few cases. You can go through editorial once for proper understanding.
This is what you are assuming brother.
You just have to focus on the mathematical side of the problem.
Where is it written that y=0 means lab is cleaned?
getting my point?
You code is failing on this input:
1
0 200
Expected output: 3
[Reason: 0(x)+101(a)+101(a)-2(b) , where ,a=101 (odd) , b=2 (even) ]
Your output: 2
Can you explain how in 2 steps you will solve this test case?