Proper Nutrition
来源:互联网 发布:淘宝网童装店哪家好 编辑:程序博客网 时间:2024/06/05 18:56
B. Proper Nutrition
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it’s possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles.
In other words, you should find two non-negative integers x and y such that Vasya can buy x bottles of Ber-Cola and y Bars bars and x·a + y·b = n or tell that it’s impossible.
Input
First line contains single integer n (1 ≤ n ≤ 10 000 000) — amount of money, that Vasya has.
Second line contains single integer a (1 ≤ a ≤ 10 000 000) — cost of one bottle of Ber-Cola.
Third line contains single integer b (1 ≤ b ≤ 10 000 000) — cost of one Bars bar.
Output
If Vasya can’t buy Bars and Ber-Cola in such a way to spend exactly n burles print «NO» (without quotes).
Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers x and y — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly n burles, i.e. x·a + y·b = n. If there are multiple answers print any of them.
Any of numbers x and y can be equal 0.
Examples
input
7
2
3
output
YES
2 1
input
100
25
10
output
YES
0 10
input
15
4
8
output
NO
input
9960594
2551
2557
output
YES
1951 1949
Note
In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.
In second example Vasya can spend exactly n burles multiple ways:
buy two bottles of Ber-Cola and five Bars bars;
buy four bottles of Ber-Cola and don’t buy Bars bars;
don’t buy Ber-Cola and buy 10 Bars bars.
In third example it’s impossible to but Ber-Cola and Bars bars in order to spend exactly n burles.
#include<iostream>#include<cstdio>using namespace std;int main(){ int n,a,b,x=0,y=0,vis=0; scanf("%d%d%d",&n,&a,&b); if(n%a==0) x=n/a,vis=1; else if(n%b==0) y=n/b,vis=1; else{ if(a>b){ x=n/a; while(x){ if((n-a*x)%b==0){ y=(n-a*x)/b; vis=1; break; } x--; } } else{ y=n/b; while(y){ if((n-b*y)%a==0){ x=(n-b*y)/a; vis=1; break; } y--; } } } if(vis){ printf("YES\n%d %d\n",x,y); } else printf("NO\n"); return 0;}
- Proper Nutrition
- codeforces 898B. Proper Nutrition
- Codeforces Round #451 (Div. 2) B. Proper Nutrition
- Codeforces Round #451 (Div. 2) B. Proper Nutrition
- Codeforces Round #451 (Div. 2) Proper Nutrition 暴力枚举
- 898BProper Nutrition
- proper fraction
- Restaurant Nutrition:美食应用新思路
- CalorieKing Nutrition & Exercise Manager v4.1.0
- Proper Screencasting on Linux
- Proper use of AsyncTask
- Proper use of comments
- #1107 : Shortest Proper Prefix
- Shortest Proper Prefix
- Always #include the proper headers
- Proper Threading in Winforms .NET
- hihocoder #1107 : Shortest Proper Prefix
- hihocoder 1107 Shortest Proper Prefix
- RocketMQ(5)——消息文件过期原理
- 贝叶斯分类器原理与应用
- DFS专练3 全排列字典序输出问题
- 朱金付第十章编程
- mac系统从移动硬盘往外考资料时提示“不能更改xx中的一个或多个项目,因为它们正在使用中”压根就没开始用
- Proper Nutrition
- Python 字符串 循环
- Qt与SQL server的连接使用
- 什么是spring boot
- RocketMQ(6)——客户端配置详解
- Gensim官方教程翻译(一)——语料库与向量空间(Corpora and Vector Spaces)
- Gym 101617J dp
- RocketMQ(7)——通信协议
- TensorFlow技术解析与实战 8 第一个tensorflow程序