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 ;
}

最新文章

  1. 配置IIS的通配符应用程序映射
  2. jquery弹出可关闭遮罩提示框
  3. Android 千牛数据库分析
  4. HDU 3605 Escape(状压+最大流)
  5. windows 下 node.js 和 express 的安装
  6. Win10/UWP新特性系列—使用打印机
  7. ios 计算缓存大小
  8. php+phpquery简易爬虫抓取京东商品分类
  9. 转载:性能优化——统计信息——SQLServer自动更新和自动创建统计信息选项
  10. hdu 1175 连连看 (广搜,注意解题思维,简单)
  11. api接口通信安全性
  12. Python re正则表达式
  13. RequireJS(一)
  14. hibernate学习(六) flush()和clean()区别和使用
  15. 关于FastDBF库读写ArcGis dbf文件的小bug
  16. RPC----Hadoop核心协议
  17. Sqlserver 锁(转)
  18. JUnit学习笔记-0-JUnit启动类
  19. Nginx自定义404页面并返回404状态码
  20. lfs(systemv版本)学习笔记-第4页

热门文章

  1. LeetCode. 颠倒二进制位
  2. Nginx学习笔记(三):Nginx 请求处理
  3. BZOJ4566 HAOI2016找相同字符(后缀自动机)
  4. 第八讲,TLS表(线程局部存储)
  5. TeamCity安装和配置
  6. 如何在含有json类型的字段上建立多列索引
  7. VBA术语(三)
  8. 解决IE8中select下拉列表文字上下不居中的问题
  9. SQL alchemy
  10. 批量删除checkbox前台后台