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.

ax+by=cax+by=c
设 d=gcd(a,b)d=gcd(a,b) 则其有解当且仅当 d|cd|c
求解方法如下:

用扩展欧几里得求出 ax0+by0=dax0+by0=d 的解

则a(x0∗c/d)+b(y0∗c/d)=ca(x0∗c/d)+b(y0∗c/d)=c
故而特解为 x′=x0∗c/d,y′=y0∗c/dx′=x0∗c/d,y′=y0∗c/d
而通解 = 特解 + 齐次解

而齐次解即为方程 ax+by=0ax+by=0的解

故而通解为 x=x′+k∗b/d,y=y′−k∗a/dk∈z

对于x首先乘那个倍数,然后x取得余数是b/d,x对这个余数取余就可以得到一个x,然后在这个余数的情况下可以求得一个y,在判断当前这个y是否正数

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;

#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef pair<int, int> PII;
typedef unsigned long long ULL;

inline int read(int out = 0)
{
    
    
    char c;
    while((c=getchar()) < 48 || c > 57);
    while(c >= 48 && c <= 57) out=out*10+c-48,c=getchar();
    return out; 
}

const int N = 1010;
const int M = 35;
const int mod = 1e9 + 7;
const int PP = 131;
const double eps = 1e-10;

int n;
int a, b;
int x, y;
int exgcd(int a, int b, int &x, int &y)
{
    
    
    if (!b)
    {
    
    
        x = 1, y = 0;
        return a;
    }
    int d = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

signed main(){
    
    
	gt(n), gt(a), gt(b);
	
	int d = exgcd(a,b, x, y);
	
//	cout << d << endl;
	if (n % d)    cout << "NO" << endl;
	else{
    
    
		x *= (n / d);
		int mod = (b / d);
		x= (x % mod + mod) % mod;
		y = (n - x * a) / b;
		if (x < 0 || y < 0){
    
    
			cout << "NO" << endl;
		}
		else{
    
    
			cout << "YES" << endl;
			cout << x << " " << y << endl;
		}
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_45772483/article/details/112790262