Buy a Shovel(暴力即可)

A. Buy a Shovel
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of “10-burle coins” and exactly one coin of r burles (1 ≤ r ≤ 9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of r burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
Input
The single line of input contains two integers k and r (1 ≤ k ≤ 1000, 1 ≤ r ≤ 9) — the price of one shovel and the denomination of the coin in Polycarp’s pocket that is different from “10-burle coins”.
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Output
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
Examples
input
Copy
117 3
output
Copy
9
input
Copy
237 7
output
Copy
1
input
Copy
15 2
output
Copy
2
Note
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can’t buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
题意:根据题目分析,可以提前去进行相关论题的证明,最多用10个10元硬币,和一个具体的硬币,最多买的话花费1009元,故而此时买的个数撑死是10件。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int k,r;
int main()
{
    
    
    while(~scanf("%d%d",&k,&r))
    {
    
    
        for(int i=1;i<=10;i++)
            if(i*k%10==0||i*k%10==r)//前者是不用零钱,后者是用零钱的情况
            {
    
    
                printf("%d\n",i);
                break;
            }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_46006714/article/details/110069556