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.

【题意】:口袋里面有无限枚 10 元和一枚 r 面值的硬币,问最少可以买多少把价值为 k 的铁铲。

【分析】:模拟。倍增k,直到为10的倍数(无限10元支付)或者减掉r后为10倍数。

【代码】:

#include <bits/stdc++.h>

using namespace std;
int main()
{
int r,k,sum;
while(cin>>k>>r)
{
sum=;
for(int i=;;i++)
{
sum=k*i;
if(sum%==||(sum-r)%==)
{
printf("%d\n",i);
break;
}
}
}
return ;
}

 

Codeforces Round #377 (Div. 2) A. Buy a Shovel【暴力/口袋里面有无限枚 10 元和一枚 r 面值的硬币,问最少可以买多少把价值为 k 的铁铲】的更多相关文章

  1. Codeforces Round #377 (Div. 2) D. Exams

    Codeforces Round #377 (Div. 2) D. Exams    题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...

  2. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  3. Codeforces Round #377 (Div. 2) A B C D 水/贪心/贪心/二分

    A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces Round #377 (Div. 2)部分题解A+B+C!

    A. Buy a Shovel 题意是很好懂的,一件商品单价为k,但他身上只有10块的若干和一张r块的:求最少买几件使得不需要找零.只需枚举数量判断总价最后一位是否为0或r即可. #include&l ...

  5. Codeforces Round #253 (Div. 1) A. Borya and Hanabi 暴力

    A. Borya and Hanabi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/442/p ...

  6. Codeforces Round #336 (Div. 2)【A.思维,暴力,B.字符串,暴搜,前缀和,C.暴力,D,区间dp,E,字符串,数学】

    A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  7. Codeforces Round #377 (Div. 2)

    #include <iostream> #include <stdio.h> #include <string.h> using namespace std; in ...

  8. Codeforces Round #377 (Div. 2)D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...

  9. Codeforces Round #377 (Div. 2) E. Sockets

    http://codeforces.com/contest/732/problem/E 题目说得很清楚,每个电脑去插一个插座,然后要刚好的,电脑的power和sockets的值相同才行. 如果不同,还 ...

随机推荐

  1. 将有效慢日志转存到数据库v2

    import re import sys import getopt import MySQLdb from subprocess import call import os host='10.76. ...

  2. 《Cracking the Coding Interview》——第13章:C和C++——题目9

    2014-04-25 20:37 题目:请设计一个字节对齐的malloc函数,配套上对应的free函数.要求这个函数分配出的内存块儿的首地址是某个值n的整数倍,n是2的整次幂,比如128.1024之类 ...

  3. 【Dual Support Vector Machine】林轩田机器学习技法

    这节课内容介绍了SVM的核心. 首先,既然SVM都可以转化为二次规划问题了,为啥还有有Dual啥的呢?原因如下: 如果x进行non-linear transform后,二次规划算法需要面对的是d`+1 ...

  4. OZ customize windows iamge

    1.之前通过修改auto文件和windows.py文件可实现自动安装OS,但是disk bus只能以IDE模式启动,进入系统自动下载运行bat文件,安装cloudbase-init和qga,及清理日志 ...

  5. dpkg.cfg

  6. 1106 Lowest Price in Supply Chain (25 分)(树的遍历)

    求叶子结点处能活得最低价格以及能提供最低价格的叶子结点的个数 #include<bits/stdc++.h> using namespace std; ; vector<int> ...

  7. 使用UltraEdit搭建自己的C/C++ IDE

    使用UltraEdit搭建自己的C/C++ IDE CodeBlocks的13.12版本啊,主要缺点是启动慢,而且在Windows上容易假死,写着写着就无响应了,然后死活活不过来.所以没办法,只好干脆 ...

  8. UVa 11426 - GCD - Extreme (II) 转化+筛法生成欧拉函数表

    <训练指南>p.125 设f[n] = gcd(1, n) + gcd(2, n) + …… + gcd(n - 1, n); 则所求答案为S[n] = f[2]+f[3]+……+f[n] ...

  9. Linux中awk后面的RS, ORS, FS, OFS 含义

    转载自http://blog.csdn.net/qq416647781/article/details/40649419   一.RS 与 ORS 差在哪   我们经常会说,awk是基于行列操作文本的 ...

  10. 软工实践 - 第十三次作业 Alpha 冲刺 (4/10)

    队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/9980005.html 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去 ...