A. Optimal Currency Exchange

time limit per test

1.5 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

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 nn 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 dd rubles, and one euro costs ee rubles.

Recall that there exist the following dollar bills: 11, 22, 55, 1010, 2020, 5050, 100100, and the following euro bills — 55, 1010, 2020, 5050, 100100, 200200 (note that, in this problem we do not consider the 500500 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 nn, ee and dd, 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 nn (1≤n≤1081≤n≤108) — the initial sum in rubles Andrew has.

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

The third line of the input contains integer ee (30≤e≤10030≤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.

Examples
input

Copy
100
60
70
output

Copy
40
input

Copy
410
55
70
output

Copy
5
input

Copy
600
60
70
output

Copy
0
Note

In the first example, we can buy just 11 dollar because there is no 11 euro bill.

In the second example, optimal exchange is to buy 55 euro and 11 dollar.

In the third example, optimal exchange is to buy 1010 dollars in one bill.

题意:用卢比换美元和欧元,要使剩下的卢比数量最少

题解:给定美元和欧元的汇率分别是 d 和  e ,d是1的倍数,e是5的倍数,枚举x( x<=n ),输出min(ans,x%d+(n-x)%e)即可

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int n,d,e,ans=;
cin>>n>>d>>e;
for(int i=;i<=n;i++)
ans=min(ans,i%d+(n-i)%e);
cout<<ans<<endl;
return ;
}

最新文章

  1. javascript 框架、根基技巧、布局、CSS、控件 JavaScript 类库
  2. 将javascript函数写在Html标签里
  3. 【腾讯Bugly干货分享】TRIM:提升磁盘性能,缓解Android卡顿
  4. Java基础-多线程
  5. the essence of the internet idea
  6. SQL Server 使用ROW_NUMBER()进行分页
  7. javascript单元测试(转)
  8. 让初学者快速了解Git
  9. c:if true、false都显示
  10. 基于Java的HashMap和HashSet实现
  11. 基于Matlab实现多次最佳一致的函数逼近(类似求渐进函数)
  12. matplotlib中color可用的颜色
  13. Python 游戏之旅(Pygame)
  14. Java学习笔记34(sql基础 :增删改查1)
  15. CentOS挂载光盘
  16. finecms如何调用多个指定栏目的内容
  17. maven工程的多环境配置方案(profile)
  18. idou老师教你学Istio: 如何用Istio实现K8S Egress流量管理
  19. 高版本的jdk编译过的项目移到低版本的JDK的eclipse中出错的问题
  20. C#设计模式--命令模式(学习Learning hard C#设计模式笔记)

热门文章

  1. 【C语言】无参函数调用实例
  2. SpringCloud全家桶学习之Feign负载均衡----Feign(四)
  3. ASP.NET Core搭建多层网站架构【7-使用NLog日志记录器】
  4. Fluent_Python_Part2数据结构,04-text-byte,文本和字节序列
  5. Linux - 查看文件、文件夹、磁盘大小命令
  6. .NET中的字符串(4):字符串 - 特殊的引用类型
  7. Python:re 模块
  8. Spring Boot Ftp Client 客户端示例支持断点续传
  9. Linux批量装机(PXE)!
  10. 用java代码打印九九乘法表