A. Optimal Currency Exchange
Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has n rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is d rubles, and one euro costs e rubles.
Recall that there exist the following dollar bills: 1, 2, 5, 10, 20, 50, 100, and the following euro bills — 5, 10, 20, 50, 100, 200 (note that, in this problem we do not consider the 500 euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.

Help him — write a program that given integers n, e and d, finds the minimum number of rubles Andrew can get after buying dollar and euro bills.

Input
The first line of the input contains one integer n (1≤n≤108) — the initial sum in rubles Andrew has.

The second line of the input contains one integer d (30≤d≤100) — the price of one dollar in rubles.

The third line of the input contains integer e (30≤e≤100) — the price of one euro in rubles.

Output
Output one integer — the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.

Input


Output


Input


Output


题意:有n个卢布,要换成美元和欧元,使手上剩余的卢克最少。一美元价值d卢布,一欧元价值e卢克。

思路:欧元的面值最小为5,则只需找5的倍数,美元最小面值为1。

写法:枚举。

AC代码:

//欧元的面值最小为5,其实的都少5的倍数,美元最小面值为1。
/*
1 dollar---> d rubles
1 euro ----> e rubles dollar 1 2 5 10 20 50 100
euro 5 10 20 50 100 200 */
#include<bits/stdc++.h> using namespace std; #define int long long signed main(){
int n,d,e;
cin>>n>>d>>e;
int ans=n;
int x1=n/e;
if(x1<){
printf("%lld\n",n-(n/d)*d);return ;
}else{
int t1=n/(e*);
for(int i=;i<=t1;i++){
int temp=n;
temp=temp-e*i*-((n-e*i*)/d)*d;
//int sum2=temp-(temp/d)*d;
ans=min(ans,temp);
}
printf("%lld\n",ans); }
return ;
}

Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题的更多相关文章

  1. Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) C题

    C. Bad Sequence Problem Description: Petya's friends made him a birthday present — a bracket sequenc ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  3. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  4. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  5. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  7. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  8. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  9. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

随机推荐

  1. [DEBUG] ubuntu mysql root@localhost改了密码还是进不去ERROR 1698 (28000)

    之前用skip-grant-tables的方法免密进入Mysql,修改了root的密码, 当时重启服务后是可以用密码进入Mysql的.结果昨天突然又进不去了:) 所以更换方法,特此记录. ====== ...

  2. Centos7.3安装jdk和maven

    安装jdk和maven             通过winscp上传jdk             解压                 tar -zxvf jdk-8u91-linux-x64.ta ...

  3. python爬虫框架scrapy 豆瓣实战

    Scrapy 官方介绍是 An open source and collaborative framework for extracting the data you need from websit ...

  4. Oracle查询部门工资最高员工的两种方法 1、MAX()函数 2、RANK()函数

      本文以SCOTT用户下初始的EMP表为参考.代码可直接使用.   查询EMP表结构的语句如下,[代码1]: DESC EMP;   EMP表结构如下:[结果1]: SQL> DESC EMP ...

  5. WUSTOJ 1274: 喂,这里是帅帅的LCM(Java)

    1274: 喂,这里是帅帅的LCM 题目   在一组数中,找出个数为奇数的数.更多内容点击标题. 分析   其实这种题并不难,做过一次之后,绝对不会错第二次.通过读题可以发现,我们要找的那个数在这一堆 ...

  6. 2019版UI学习路线(含大纲+视频+工具+网盘+面试题)

    2019最新UI设计师教程(学习路线+课程大纲+视频教程+面试题+学习工具) 什么是全链路UI设计 UI设计师是随着网络而兴起的新兴设计行业,从事对软件的人机交互.操作逻辑.界面美观的整体设计工作.涉 ...

  7. (六)mybatis之多对一关系(简单)

    一.需求分析 需求:   查询所有订单信息及订单下的订单明细信息 分析:      一条订单只能由一个消费者下单,但是一条订单有多条订单明细. 二.创建数据库表和实体对象 Customer.java ...

  8. 【原创】大叔经验分享(85)ssh秘钥之创建和使用

    一 创建秘钥 1 Macbook $ ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to sa ...

  9. cli create ssl certkey

    cli create ssl certkey ############################### # 创建CA密钥 create ssl rsakey bwsrv-root.key -ex ...

  10. Redis 简单使用 and 连接池(python)

    Redis 简介 NoSQL(not only sql):非关系型数据库 支持 key-value,  list,  set,  zset,  hash 等数据结构的存储:支持主从数据备份,集群:支持 ...