A Journey Towards One

Given N. You can perform 3 types of operations:

You have to find the minimum number of operations needed to reach 1.


This is a companion discussion topic for the original entry at https://toph.co/p/a-journey-towards-one

In the test case the minimum number of making 23 into 1 is 7 in my sense.

  1. decrease 23 by 1.it becomes 22
  2. divide 22 by 2. it becomes 11
  3. decrease 11 by 1. it becomes 10
  4. divide 10 by 2. it becomes 5
  5. decrease 5 by 1. it becomes 4
  6. divide 4 by 2. it becomes 2
  7. divide 2 by 2. it becomes 1

why 6? can anyone explain it?

How about this?

23 -> 24 -> 12 -> 6 -> 3 -> 2 -> 1
1 Like