Buy a Shovel

简介: Buy a Shovel

文章目录

一、Buy a Shovel

总结


一、Buy a Shovel

本题链接:Buy a Shovel


题目:

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.


本博客给出本题截图:

image.png

image.png

题意:输入两个数kr,问你可以使用无数个10和一个r,问需要多少个k可以使得可以用无数个10(可以不用10)和一个r(可以不用r)组成

AC代码

#include <iostream>
#include <string>
using namespace std;
int main()
{
    string k;
    int r;
    cin >> k >> r;
    int t = k[k.size() - 1] - '0';
    if (t == r || t == 0)
    {
        cout << 1;
        exit(0);
    }
    else if (t == 5)
    {
        cout << 2;
        exit(0);
    }
    else 
    {
        for (int i = 2; i < 10; i ++ )
            if ((i * t) % 10 == r || !((i * t) % 10))
            {
                cout << i;
                break;
            }
    }
    return 0;
}

总结

水题,不解释


目录
相关文章
|
11月前
|
存储 Linux C++
【PAT甲级 - C++题解】1092 To Buy or Not to Buy
【PAT甲级 - C++题解】1092 To Buy or Not to Buy
37 0
|
算法
LeetCode 123. Best Time to Buy and Sell Stock III
给定一个数组,它的第 i 个元素是一支给定的股票在第 i 天的价格。 设计一个算法来计算你所能获取的最大利润。你最多可以完成 两笔 交易。 注意: 你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。
75 0
LeetCode 123. Best Time to Buy and Sell Stock III
|
算法
LeetCode 121. Best Time to Buy and Sell Stock
给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。 如果您最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润。
50 0
LeetCode 121. Best Time to Buy and Sell Stock
|
算法
LeetCode 188. Best Time to Buy and Sell Stock IV
给定一个数组,它的第 i 个元素是一支给定的股票在第 i 天的价格。 设计一个算法来计算你所能获取的最大利润。你最多可以完成 k 笔交易。
60 0
LeetCode 188. Best Time to Buy and Sell Stock IV
Leetcode-Easy 121. Best Time to Buy and Sell Stock
Leetcode-Easy 121. Best Time to Buy and Sell Stock
103 0
Leetcode-Easy 121. Best Time to Buy and Sell Stock
【1092】To Buy or Not to Buy (20 分)
【1092】To Buy or Not to Buy (20 分) 【1092】To Buy or Not to Buy (20 分)
71 0
|
vr&ar 双11 Android开发
阿里BUY+的前世今生和未来之路
GM LAB在2016年3月成立,是一个旨在探索最新电商购物体验的实验室。在探索VR购物的过程中,有两个需要核心解决的问题:一个是VR购物的产品形态是什么,另一个是VR环境下的店铺和商品怎么来。对于这两个问题,我们分别发起了BUY+和造物神计划去解决。
2674 0
1092. To Buy or Not to Buy (20) simple
#include using namespace std; int main(int argc, const char * argv[]) { // insert code here.
816 0