Codeforces Round #451 (Div. 2) Proper Nutrition 暴力枚举

来源:互联网 发布:韩国股市行情软件下载 编辑:程序博客网 时间:2024/06/07 15:37

Proper Nutrition

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.

题目的意思就是让你求二元一次不定方程c=ax+by的正整数根,我原以为要用扩展欧几里德来计算……没想到暴力也能过

#include<bits/stdc++.h>using namespace std;bool ok=false;int main(){  long long n,a,b,x,y;  cin>>n>>a>>b;  for(int i=0;i<=n;i++)//枚举x    { int c=(n-a*i)/b;      if(c>=0&&(a*i+b*c)==n)      {        x=i;y=c;        ok=true;        break;      }    }  if(ok)    {      cout<<"YES"<<endl;      cout<<x<<endl;      cout<<y<<endl;    }    else    cout<<"NO"<<endl;}
阅读全文
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 淘宝号黑号了怎么办… 中通包裹异常怎么办 包裹退回去了怎么办 qq支付密码错误怎么办 ie8出现闪退怎么办 平板输不了密码怎么办 华硕笔记本键盘打不开怎么办 电脑打不开rar文件怎么办 苹果手机淘宝卡怎么办 淘宝联盟网址打不开怎么办 淘宝买东西卖家不退货怎么办 手机清理后微信打不开视频怎么办 搜索历史已关闭怎么办 微博重新激活怎么办 淘宝直播反应慢怎么办 微信新设备无法登录怎么办 dnf自动连接失败怎么办 APP注册没有成功怎么办 忘记绑定微信号怎么办 淘宝钻石绣被骗怎么办 safari出现闪退怎么办 12123手机号被占用怎么办 12306换手机了怎么办 51串口打开失败怎么办 打开com串口失败怎么办 xp串口打开失败怎么办 台式电脑没光驱怎么办 相机功能用不了怎么办 支付宝登录失败怎么办 淘宝号限制登陆怎么办 海信电视看不了怎么办 淘宝不记得密码怎么办 淘宝号忘记了怎么办 号码注销支付宝怎么办 旺旺号限制登录怎么办 淘宝单被监控了怎么办 晚上手机网速慢怎么办 卖家淘金币怎么办 淘宝不能下单怎么办 淘宝店铺失效了怎么办 淘宝订单没货怎么办