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 e rubles.

Recall that there exist the following dollar bills: 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 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 1≤n≤108) — the initial sum in rubles Andrew has.

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

The third line of the input contains integer 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.

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 1 euro bill.

In the second example, optimal exchange is to buy 1 dollar.

In the third example, optimal exchange is to buy 10 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=99999999;
    cin>>n>>d>>e;
    for(int i=0;i<=n;i++)
        ans=min(ans,i%d+(n-i)%e);
    cout<<ans<<endl;
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-11-30
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2021-11-15
  • 2022-01-28
  • 2021-11-20
  • 2022-12-23
相关资源
相似解决方案