Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- using namespace std;
- void diff(vector < int >&a, vector < int >b, int k = 1);
- void diofant(int a, int b, int c, int &x, int &y);
- int main()
- {
- int a = -11, b = -58, c = 100, x, y;
- diofant(abs(a), abs(b), c, x, y);
- if (a < 0)
- x = -x;
- if (b < 0)
- y = -y;
- cout << " x = " << x << "+ (" << -b << ")t" << endl;
- cout << " y = " << y << "+ (" << a << ")t" << endl;
- auto flag = a * x + b * y == c ? "true" : "false";
- cout << "Checking : " << flag;
- return 0;
- }
- void diff(vector < int >&a, vector < int >b, int k)
- {
- for (int i = 0; i < a.size(); a[i++] -= k * b[i]);
- }
- void diofant(int a, int b, int c, int &x, int &y)
- {
- vector < int >v = { a, c, 0 }, w =
- {
- b, 0, c};
- while (v[0] != 0 && w[0] != 0)
- {
- if (v[0] >= w[0])
- diff(v, w);
- else
- diff(w, v);
- }
- if (v[0] == 0)
- {
- x = w[1];
- y = w[2];
- }
- else
- {
- x = v[1];
- y = v[2];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement