# Minimum decrements to make integer A divisible by integer B

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.

Examples:

```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.
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach:

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:

## C++

 `// C++ implementation to count ` `// Total numbers moves to make ` `// integer A divisible by integer B ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// Function that print number ` `// of moves required ` `void` `movesRequired(``int` `a, ``int` `b) ` `{ ` `    ``// calculate modulo ` `    ``int` `total_moves = a % b; ` ` `  `    ``// print the required answer ` `    ``cout << total_moves << ``"\n"``; ` `} ` ` `  `// Driver Code ` `int` `main() ` `{ ` ` `  `    ``// initialise A and B ` `    ``int` `A = 10, B = 3; ` ` `  `    ``movesRequired(A, B); ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java implementation to count ` `// total numbers moves to make ` `// integer A divisible by integer B ` `import` `java.util.*; ` ` `  `class` `GFG{ ` ` `  `// Function that print number ` `// of moves required ` `static` `void` `movesRequired(``int` `a, ``int` `b) ` `{ ` `     `  `    ``// Calculate modulo ` `    ``int` `total_moves = a % b; ` ` `  `    ``// Print the required answer ` `    ``System.out.println(total_moves); ` `} ` ` `  `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` `     `  `    ``// Initialise A and B ` `    ``int` `A = ``10``, B = ``3``; ` ` `  `    ``movesRequired(A, B); ` `} ` `} ` ` `  `// This code is contributed by offbeat `

## Python3

 `# Python3 implementation to count ` `# total numbers moves to make ` `# integer A divisible by integer B ` ` `  `# Function that print number ` `# of moves required ` `def` `movesRequired(a, b): ` `     `  `    ``# Calculate modulo ` `    ``total_moves ``=` `a ``%` `b ` ` `  `    ``# Print the required answer ` `    ``print``(total_moves) ` ` `  `# Driver Code ` `if` `__name__ ``=``=` `'__main__'``: ` `     `  `    ``# Initialise A and B ` `    ``A ``=` `10` `    ``B ``=` `3` ` `  `    ``movesRequired(A, B) ` ` `  `# This code is contributed by Samarth `

## C#

 `// C# implementation to count ` `// total numbers moves to make ` `// integer A divisible by integer B ` `using` `System; ` `class` `GFG ` `{ ` ` `  `// Function that print number ` `// of moves required ` `static` `void` `movesRequired(``int` `a, ``int` `b) ` `{ ` `     `  `    ``// Calculate modulo ` `    ``int` `total_moves = a % b; ` ` `  `    ``// Print the required answer ` `    ``Console.Write(total_moves); ` `} ` ` `  `// Driver code ` `public` `static` `void` `Main(String []args) ` `{ ` ` `  `    ``// Initialise A and B ` `    ``int` `A = 10, B = 3; ` ` `  `    ``movesRequired(A, B); ` `} ` `} ` ` `  `// This code is contributed by shivanisinghss2110 `

Output:

```1
```

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.

My Personal Notes arrow_drop_up Interns at Geeksforgeeks

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.