Given a number, the only operation allowed is to multiply the number by 2. Calculate the minimum number of operations to make the number divisible by 10.
NOTE: If it is not possible to convert then print -1.
As the given number is itself divisible by 10,
the answer is 0.
As by multiplying with 2, given no. can’t be
converted into a number that is divisible by 10,
therefore the answer is -1.
Approach: Any given number is divisible by 10 only if the last digit of the number is 0. For this problem, extract the last digit of the input number and check it in the following ways :
1) If the last digit is 0 then it is already divisible by 10 , so the minimum number of steps is 0.
2) If the last digit is 5 then multiplying it by 2 one time will make it divisible by 10, so the minimum number of steps is 1.
3) If the last digit is an even or odd number (apart from 0 and 5) then multiplying it by 2 any number of times will only produce even number so we can never make it divisible by 10. Therefore the number of steps is -1.
- Find the smallest number whose digits multiply to a given number n
- Count the number of pairs (i, j) such that either arr[i] is divisible by arr[j] or arr[j] is divisible by arr[i]
- Smallest number to multiply to convert floating point to natural
- Check if a number is divisible by all prime divisors of another number
- Number of digits to be removed to make a number divisible by 3
- Find if a number is divisible by every number in a list
- Number is divisible by 29 or not
- Number of divisors of a given number N which are divisible by K
- Check if a number is divisible by 23 or not
- Rearrangement of a number which is also divisible by it
- Check if a number is divisible by 41 or not
- Numbers that are not divisible by any number in the range [2, 10]
- Check if a large number is divisible by 13 or not
- Check if a large number is divisible by 75 or not
- Largest number divisible by 90 that can be made using 0 and 5
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.