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. Scratch编程:牛顿的苹果——地心引力

    牛顿的苹果 同学们,你们知道牛顿的苹果的故事吗? 传说1665年秋季,牛顿坐在自家院中的苹果树下苦思着行星绕日运动的原因.这时,一只苹果恰巧落下来,它落在牛顿的脚边.就是这个偶尔的瞬间,牛顿发现了苹果 ...

  2. uboot-的start.S详细注解及分析

    原文地址:uboot-的start.S详细注解及分析 作者:zhouyg11 大多数bootloader都分为stage1和stage2两部分,u-boot也不例外.依赖于CPU体系结构的代码(如设备 ...

  3. uboot 与 代码重定位

    ref: https://blog.csdn.net/dhauwd/article/details/78566668 https://blog.csdn.net/yueqian_scut/articl ...

  4. (十一)mybatis之整合ehcache缓存

    一.二级缓存 大家都知道使用mybatis就要先获取sqlsessionfactory,继而使用sqlsession来和数据库交互,每次只需要使用sqlsession对象提供的方法就好,当我们需要第一 ...

  5. 一个因MySQL大小写敏感导致的问题

    做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! 00 MYSQL对大小写敏感 见字如面,见标题知内容.你有遇到过因为MYSQL对大小写敏感而被坑的体验吗? 之前看过阿里巴 ...

  6. ASP.NET Core 入门(1)(搭建环境CentOS)

    一.CentOS 7 安装 下载CentOS http://isoredirect.centos.org/centos/7/isos/x86_64/  选择其中下载即可. 下载完成后打开vmware准 ...

  7. 二、运行时JVM结构组成及作用

    二.运行时JVM结构组成及作用 程序计数器 是否共享:否,线程私有,每个线程有1个独立的程序计数器! 所处位置:线程私有的内部区域 生命周期:与线程绑定 主要作用: 当前线程执行字节码的行号指示器!  ...

  8. Python练习_集合和深浅拷贝_day7

    1. 1.作业 1.把列表中所有姓周的人的信息删掉(升级题:此题有坑, 请慎重): lst = ['周老二', '周星星', '麻花藤', '周扒皮'] 结果: lst = ['麻花藤'] 2.车牌区 ...

  9. Microsoft Internet Explorer v11 XML External Entity Injection 0day

    [+] Credits: John Page (aka hyp3rlinx) [+] Website: hyp3rlinx.altervista.org[+] Source:  http://hyp3 ...

  10. 【数字图像处理】目标检测的图像特征提取之HOG特征

    1.HOG特征 方向梯度直方图(Histogram of Oriented Gradient, HOG)特征是一种在计算机视觉和图像处理中用来进行物体检测的特征描述子.它通过计算和统计图像局部区域的梯 ...