CodeForces-732A-Buy a Shovel(水题)
来源:互联网 发布:58发帖神器软件 编辑:程序博客网 时间:2024/06/09 20:31
A. Buy a Shovel
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
题意:给出K和R,代表铲子的价格和一个R面值的硬币,此时有无数个面值为10的硬币可以使用,购买N个铲子使得手里的钱刚好花完,输出最小的N。
思路:手里的钱也就是无数个面试为10的硬币加上一个面值R的硬币,也就是找到最小的N使得N*K%10==0||N*K%10==R,由于R在1~9之间,只需枚举N从1~10即可
代码
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<math.h>using namespace std;int main(){ int K,R; scanf("%d%d",&K,&R); int N=1; while(K*N%10!=0&&K*N%10!=R) N++; printf("%d\n",N); return 0;}
- codeforces 732A Buy a Shovel(水题)
- CodeForces-732A-Buy a Shovel(水题)
- 【71.76%】【codeforces 732A】Buy a Shovel
- Codeforces 732A.Buy a Shovel
- CodeForces 732A Buy a Shovel
- Codeforces 732A-Buy a Shovel
- CodeForces 732A 之 Buy a Shovel
- CodeForces 732 A.Buy a Shovel(水~)
- codeforces——732A——Buy a Shovel
- A. Buy a Shovel
- A. Buy a Shovel
- CodeForces 732A Buy a Shovel(买铁铲不找零,掉分继续)
- Buy a Shovel
- Codeforces Round #377 (Div. 2) A. Buy a Shovel
- codeforces732A A. Buy a Shovel
- CodeForces 487A(水题)
- codeforces 427A(水题)
- CodeForces 598A (水题)
- spring源码分析之aop
- 极光推送
- 当VC问你商业模式的时候 他们在问什么?
- WinEdt+CTeX+pst-optic宏包使用初体验
- spring源码分析之事物
- CodeForces-732A-Buy a Shovel(水题)
- 安装交叉调试器gdb,编译出错cc1: warnings being treated as errors
- yii2中自定义验证规则rules
- 用 Flask 来写个轻博客 (11) — M(V)C_创建视图函数
- 数据结构实验之数组二:稀疏矩阵
- Android自定义View(LimitScrollerView-仿天猫广告栏上下滚动效果)
- Spring中AOP的两种代理方式(Java动态代理和CGLIB代理)
- 用java写一个电子书阅读器,怎么进行自动内码识别,求大神指教
- JavaWeb--基本接口问题