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?

If

x = 1, y = 7

then, x+5, x+1

can be done in these two steps.

Also, if

x = 4, y = 12

(y-x) = 8, divisible by 4

Is it not correct to do in two steps by adding 7,and then adding 1??

you can’t change a or b more than once.

How can we know for sure that for the case X > Y , there will only two possibilities unlike for case X>Y where there are three possibilities.

for X >Y ,

we have to decrease X so obviously we will use b.

if X-Y==even , then definitely ,

1 step(minimum) is needed as we will take b=X-Y

if X-Y==Odd , Can we do it in 1 step ? Not possible,Right ?

If 1 can’t be taken as minimum no. of steps ,

we will surely prefer 2 as minimum no. of steps (Greedy)

Check whether 2 steps are possible for this case?

Yes it’s possible!

Add odd number(a) to X -------------------------(1st step)

Now, $X-Y=even , simply use b=X-Y------(2nd step)

As you know , 2 steps are minimum and we can’t do better than this.So why to think another possibility?

In X<Y, Minimum steps can be greater than 2,So we think of another possiblities to do minimize total number of steps.

You can check this explaination too - Click Here

thk

a and b are constants hence we can’t change them.

ok. thanks a lot

py_compile.PyCompileError: Sorry: TabError: inconsistent use of tabs and spaces in indentation (prog.py, line 6)

i am getting this error again and again with you code in Python.

help me out

I have corrected it.

hey brother

sorry to interrupt

if i have to go from 2 to 10

the difference is 8

i can do it in 2+ 7+1 = 10

making it only 2 steps

adding odd 7 and adding odd 1