zoukankan      html  css  js  c++  java
  • 小凯的疑惑

    链接:https://ac.nowcoder.com/acm/problem/16414
    来源:牛客网

    小凯手中有两种面值的金币,两种面值均为正整数且彼此互素。每种金币小凯都有无数个。在不找零的情况下,仅凭这两种金币,有些物品他是无法准确支付的。现在小凯想知道在无法准确支付的物品中,最贵的价值是多少金币?注意:输入数据保证存在小凯无法准确支付的商品。


    小凯手中有面值为3和7的金币无数个,在不找零的前提下无法准确支付价值为 1、2、4、5、8、11的物品,其中最贵的物品价值为11。
    比11贵的物品都能买到,比如:
    12 = 3 x 4 + 7 x 0
    13 = 3 x 2 + 7 x1
    14 = 3 x 0 + 7 x 2
    15 = 3 x 5 + 7 x 0

    因为题目给我们两个互素的两个数,那么我们先找出两个数的最小公倍数(即x*y),然后这个数减去两个数即为结果;

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<iostream>
    #include<algorithm>
    #define ll long long
    using namespace std;
    
    int main()
    {
        ll x, y;
        cin >> x >> y;
        cout << x * y - x - y << endl;
    }
  • 相关阅读:
    跟我一起写 Makefile
    NFS服务器配置
    q
    tar命令的详细解释
    etc/xinetd.d目录介绍
    ubuntu 10.04下的配置tftp服务器
    莫队板子
    Day8(分块)
    字符串板子
    字符串练习题
  • 原文地址:https://www.cnblogs.com/csxaxx/p/13330209.html
Copyright © 2011-2022 走看看