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
- Queries to multiply the given subarray with given number X and print sum
- 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
- Number of ways to split a binary number such that every part is divisible by 2
- Minimum number of swaps required to make a number divisible by 60
- Number of digits to be removed to make a number divisible by 3
- Check if a number is divisible by all prime divisors of another number
- Number of substrings with length divisible by the number of 1's in it
- 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 the number is divisible 43 or not
- Check if the given number is divisible by 71 or not
- Find the Kth number which is not divisible by N