Operacije
Dule was very bored at maths so he decided to play a game...
He told his friend to write a huge integer n on paper and then he claimed he is capable of making it into a 0 by using these operations:
1. Adding 1 to the number
2. Subtracting 1 from the number
3. Dividing by 2 (if the number is divisible)
Dule needs to find the least number of operations to reduce the number n to 0. He has asked for your help because that number n can be very big(up to 1000 digits)
He told his friend to write a huge integer n on paper and then he claimed he is capable of making it into a 0 by using these operations:
1. Adding 1 to the number
2. Subtracting 1 from the number
3. Dividing by 2 (if the number is divisible)
Dule needs to find the least number of operations to reduce the number n to 0. He has asked for your help because that number n can be very big(up to 1000 digits)
InputFirst line contains the number n(number of digits of n is less or equal to 1000) that we need to reduce to 0
OutputFirst line should contain the minimal number of operations required to reduce n to 0
Input
Output
Input
Output
5Output
4Input
30Output
7Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.