 # PONGAL2 - Editorial

Author: S R Harinya Devi
Tester: S R Harinya Devi
Editorialist: S R Harinya Devi

EASY

# PREREQUISITES:

Math, Modular-arithmetic

# PROBLEM:

Given the cost of one sugarcane, the value of the special coin and an unlimited number of 10-rupee coins, find the minimum number of sugarcanes that can be bought using the 10-rupee coins and the special coin only (using the special coin is not mandatory if the sugarcanes can be bought using the 10-rupee coins itself).

# EXPLANATION:

\mathbf{Inputs:} k (the price of one sugarcane) and r (the value of the special coin)

\mathbf{Output:} the minimum number if sugarcanes that Rohan can buy using the given coins only.

If k is a multiple of 10, then one sugarcane can be bought using the 10-rupee coins.
If k is not a multiple of 10, then we’ll have to check if k % 10 is equal to r. In this case, we can use the 10-rupee coins and the special coins.
We should keep increasing the number of sugarcanes to be bought until one of the above conditions is met.

To understand this better, let us take a few examples.

\mathbf{Example 1:}
k = 234 (price of one sugarcane), r = 2 (value of the special coin)
Firstly, we should check if k is a multiple of 10 (if true, then Rohan can just buy one sugarcane)
234 % 10 != 0

Now we should check if 234 % 10 is equal to the value of the special coin (if true he can buy one sugarcane)
234 % 10 = 4 which is not equal to the value of the special coin.

So, Rohan can’t buy one sugarcane. So we’ll have to check if he can buy 2 sugarcanes without any change.
234 * 2 = 468

Now we have to check if we can use the coins and get the sum of 468. We’ll have to follow a similar procedure. Check if 468 % 10 == 0 or 468 % 10 == (value of special coin)
468 % 10 = 8 => from which we can conclude that he can’t just buy 2 sugarcanes.

Now we should check if he can buy 3 sugarcanes. 234 * 3 = 702. Checking the value of 702 % 10, we get 2, which is equal to the value of the special coin.
So Rohan can just buy 3 sugarcanes with only using the coins he has and without any change.

\mathbf{Example 2}:
k = 15 (price of one sugarcane), r = 2(value of the special coin)
Doing a similar procedure, 15 % 10 = 5 (not equal to 0 or r).

Hence, calculating for 2 sugarcanes. 15 * 2 = 30.
30 % 10 = 0 => which can be bought using the 10-rupee coins and there is no need if using the special coin also.
Hence, the minimum number of sugarcanes he can buy is 2.

# SOLUTIONS:

Setter's Solution
    #include "bits/stdc++.h"
using namespace std;

int main()
{
int k,r,ans=1;
cin>>k>>r;
while((k*ans)%10 != 0 && (k*ans)%10 != r)
{
ans+=1;
}

cout<<ans;

}