Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <math.h>
- #include <algorithm>
- #include <vector>
- #include <string.h>
- #define F first
- #define S second
- using namespace std;
- int f;
- int gcd(int x, int y)
- {
- while (x != 0 && y != 0)
- {
- if (x > y)
- x %= y;
- else
- y %= x;
- }
- return x + y;
- }
- void gcd_ext(int a, int b, int &x, int &y)
- {
- if (a < b)
- swap(a, b);
- if (b == 0)
- {
- x = 1;
- y = 1;
- return;
- }
- int x1, y1;
- gcd_ext(b, a % b, x1, y1);
- x = y1;
- y = x1 - y1 * f;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
- //freopen("console.in", "r", stdin);freopen("console.out", "w", stdout);
- int a, b, c;
- cin >> a >> b >> c;
- int g = gcd(a, b);
- if (c % g > 0)
- {
- cout << "No solution" << endl;
- return 0;
- }
- f = a / b;
- int x, y;
- gcd_ext(a, b, x, y);
- x *= c / g;
- y *= c / g;
- cout << x << " " << y << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement