Given two positive integers A and B where A is greater than B. In one move one can decrease A by 1 which implies that after one move A is equal to A – 1. The task is to find the minimum number of moves required to make A divisible by B in constant time.
Input : A = 10, B = 3 Output : 1 Explanation: Only one move is required A = A - 1 = 9, which is divisible by 3. Input : A = 10, B = 10 Output : 0 Explanation: Since A is equal to B therefore zero move required.
To solve the problem mentioned above we take the modulus of the numbers that are A % B and the result is stored in a variable which is the required answer.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimize increments or decrements required to make sum and product of array elements non-zero
- Count decrements to nearest smaller element required to make all array elements equal
- Minimum decrements required such that sum of all adjacent pairs in an Array does not exceed K
- Find K that requires minimum increments or decrements of array elements to obtain a sequence of increasing powers of K
- Minimum Decrements on Subarrays required to reduce all Array elements to zero
- Minimize subarray increments/decrements required to reduce all array elements to 0
- Minimize positive product of two given numbers by at most N decrements
- Maximize absolute difference between X and Y by at most N decrements
- Minimize increments or decrements by 2 to convert given value to a perfect square
- Minimum operations required to make all Array elements divisible by K
- Minimum number of given moves required to make N divisible by 25
- Minimum swaps required to make a binary string divisible by 2^k
- Minimum number of swaps required to make a number divisible by 60
- Minimum and maximum number of digits required to be removed to make a given number divisible by 3
- Minimum positive integer divisible by C and is not in range [A, B]
- Find permutation of n which is divisible by 3 but not divisible by 6
- 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]
- Print digit's position to be removed to make a number divisible by 6
- Possible to make a divisible by 3 number using all digits in an array
- Number of digits to be removed to make a number divisible by 3
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.