Pagini recente » Cod sursa (job #1271682) | Cod sursa (job #2910971) | Cod sursa (job #417503) | Cod sursa (job #1099166) | Cod sursa (job #2476639)
#include <iostream>
#include <fstream>
using namespace std;
long long A, B, C;
bool euclid(long long a, long long b, long long &x, long long &y){
if(b == 0){
y = 0;
x = 1;
return C % a == 0;
}
if(euclid(b, a%b, x, y)){
long long x1 = x, y1 = y;
y = x1 - a / b * y1;
x = y1;
return true;
}
return false;
}
int main() {
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int n;
f>>n;
for (int i = 0; i < n; ++i) {
f>>A>>B>>C;
long long x, y;
if(euclid(A, B, x, y))
g<<x<<" "<<y<<"\n";
else g<<0<<" "<<0<<"\n";
}
return 0;
}