CodeForces - 732A Buy a Shovel 解题

本文介绍了一个简单的算法问题——如何确定购买特定数量的铲子以便使用特定面额的硬币支付而不需要找零。通过一个C语言程序实现了解决方案,并提供了几个示例输入输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                         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
117 3
Output
9
Input
237 7
Output
1
Input
15 2
Output
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.

 

本人英语特差,所以用的翻译器,结果翻译的结果特乱,后来看了半天才明白了题意,原来这么简单~~~

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int i=1,j,k,n=0;
 5     scanf("%d%d",&j,&k);
 6     while(1)
 7     {
 8         n+=j;
 9         if(n%10==k||n%10==0)
10         {
11             printf("%d",i);
12             return 0;
13         }
14         i++;
15     }
16 }

 

转载于:https://www.cnblogs.com/lyf0031/p/7205001.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值