Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- bool diophant(int a, int b, int c, int& x, int& y){
- stack<int> q; int r;
- while ( a % b != 0 ){
- r = a % b;
- q.push(a/b);
- a = b;
- b = r;
- }
- if ( b != 1 ) {
- return false;
- } else {
- int temp;
- x = 1; y = q.top(); q.pop();
- while ( !q.empty() ){
- temp = x;
- x = - y;
- y = - temp - q.top()*y;
- q.pop();
- }
- x *= c; y *= -c;
- return true;
- }
- }
- int main(){
- int a, b, c, x, y;
- cout << "Input a, b and c (ax + by = c): ";
- cin >> a >> b >> c;
- if ( diophant(a,b,c,x,y) ){
- cout << "x = " << x << " - " << b << "*t" << endl;
- cout << "y = " << y << " + " << a << "*t";
- } else {
- cout << "It isn't Diophantine equation!";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement