You have an unlimited number of 10-rupee coins and exactly one coin of r rupee and you need to buy minimum items each of cost k such that you do not ask for change.

**Examples:**

Input: k = 15, r = 2

Output: 2

You should buy two cables and pay 2*15=30 rupees. It is obvious that you can pay this sum without any change.Input: k = 237, r = 7

Output:1

It is enough for you to buy one cable.

It is obvious that we can pay for 10 items without any change (by paying the required amount of 10-rupee coins and not using the coin of r rupee). But perhaps you can buy fewer hammers and pay without any change. Note that you should buy at least one item.

## C++

`#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `int` `minItems(` `int` `k, ` `int` `r) ` `{ ` ` ` `// See if we can buy less than 10 items ` ` ` `// Using 10 Rs coins and one r Rs coin ` ` ` `for` `(` `int` `i = 1; i < 10; i++) ` ` ` `if` `((i * k - r) % 10 == 0 || ` ` ` `(i * k) % 10 == 0) ` ` ` `return` `i; ` ` ` ` ` `// We can always buy 10 items ` ` ` `return` `10; ` `} ` ` ` `int` `main() ` `{ ` ` ` `int` `k = 15; ` ` ` `int` `r = 2; ` ` ` `cout << minItems(k, r); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of above approach ` `import` `java.util.*; ` ` ` `class` `GFG ` `{ ` `static` `int` `minItems(` `int` `k, ` `int` `r) ` `{ ` ` ` `// See if we can buy less than 10 items ` `// Using 10 Rs coins and one r Rs coin ` `for` `(` `int` `i = ` `1` `; i < ` `10` `; i++) ` ` ` `if` `((i * k - r) % ` `10` `== ` `0` `|| ` ` ` `(i * k) % ` `10` `== ` `0` `) ` ` ` `return` `i; ` ` ` ` ` `// We can always buy 10 items ` ` ` `return` `10` `; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String args[]) ` `{ ` ` ` `int` `k = ` `15` `; ` ` ` `int` `r = ` `2` `; ` ` ` `System.out.println(minItems(k, r)); ` `} ` `} ` ` ` `// This code is contributed ` `// by SURENDRA_GANGWAR ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of above approach ` ` ` `def` `minItems(k, r) : ` ` ` ` ` `# See if we can buy less than 10 items ` ` ` `# Using 10 Rs coins and one r Rs coin ` ` ` `for` `i ` `in` `range` `(` `1` `, ` `10` `) : ` ` ` `if` `((i ` `*` `k ` `-` `r) ` `%` `10` `=` `=` `0` `or` ` ` `(i ` `*` `k) ` `%` `10` `=` `=` `0` `) : ` ` ` `return` `i ` ` ` ` ` `# We can always buy 10 items ` ` ` `return` `10` `; ` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `k, r ` `=` `15` `, ` `2` `; ` ` ` `print` `(minItems(k, r)) ` ` ` `# This code is contributed by Ryuga ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of above approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` `static` `int` `minItems(` `int` `k, ` `int` `r) ` `{ ` ` ` `// See if we can buy less than 10 items ` `// Using 10 Rs coins and one r Rs coin ` `for` `(` `int` `i = 1; i < 10; i++) ` ` ` `if` `((i * k - r) % 10 == 0 || ` ` ` `(i * k) % 10 == 0) ` ` ` `return` `i; ` ` ` ` ` `// We can always buy 10 items ` ` ` `return` `10; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main() ` `{ ` ` ` `int` `k = 15; ` ` ` `int` `r = 2; ` ` ` `Console.WriteLine(minItems(k, r)); ` `} ` `} ` ` ` `// This code is contributed ` `// by inder_verma ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// See if we can buy less than 10 items ` `// Using 10 Rs coins and one r Rs coin ` `function` `minItems(` `$k` `, ` `$r` `) ` `{ ` ` ` `for` `(` `$i` `= 1; ` `$i` `< 10; ` `$i` `++) ` ` ` `if` `((` `$i` `* ` `$k` `- ` `$r` `) % 10 == 0 || ` ` ` `(` `$i` `* ` `$k` `) % 10 == 0) ` ` ` `return` `$i` `; ` ` ` ` ` `// We can always buy 10 items ` ` ` `return` `10; ` `} ` ` ` `// Driver Code ` `$k` `= 15; ` `$r` `= 2; ` `echo` `minItems(` `$k` `, ` `$r` `); ` ` ` `// This code is contributed by Rajput-Ji ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

2

## Recommended Posts:

- Minimum cost for acquiring all coins with k extra coins allowed with every coin
- Minimum number of coins that can generate all the values in the given range
- Greedy Algorithm to find Minimum number of Coins
- Minimum number of distinct elements after removing M items | Set 2
- Get maximum items when other items of total cost of an item are free
- Minimum change in given value so that it lies in all given Ranges
- Check if given coins can be used to pay a value of S
- Path traversed using exactly M coins in K jumps
- Burst Balloon to maximize coins
- Probability of getting two consecutive heads after choosing a random coin among two different types of coins
- Find the top K items with the highest value
- Find K items with the lowest values
- Ways to place 4 items in n^2 positions such that no row/column contains more than one
- Maximum profit by selling N items at two markets
- Check if two items can be selected from two different categories without exceeding price
- Maximum items that can be bought from the cost Array based on given conditions
- Count of ways to distribute N items among 3 people with one person receiving maximum
- Coin Change | DP-7
- Change the given string according to the given conditions
- Change in Median of given array after deleting given elements

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.