Pagini recente » Istoria paginii runda/oji_in_iulie_lol/clasament | Istoria paginii runda/oni2011_ziua2 | Cod sursa (job #2760002) | Cod sursa (job #1425187) | Cod sursa (job #1604488)
#include <iostream>
#include <fstream>
using namespace std;
struct triple{
int first, second, third;
triple(const int a, const int b, const int c):
first(a), second(b), third(c){}
};
triple euclid_extins(const int a, const int b){
if(b == 0){
return triple(1, 0, a);
}
const triple tmp = euclid_extins(b, a%b);
const int x_ = tmp.second, y_ = tmp.first, g = tmp.third;
// a * x + b * y = g
// a * x - b*(a/b)*x + b*(a/b)*x + b*y = g
// (a%b)*x + b * (y + (a/b)*x)
return triple(x_, y_ - x_*(a/b), g);
}
void solve(ifstream& f, ofstream& g){
int a, b, c;
f >> a >> b >> c;
triple t = euclid_extins(a, b);
if(c%t.third != 0){
g << "0 0\n";
return;
}
const int nr = c / t.third;
g << (t.first * nr) << ' ' << (t.second * nr) << '\n';
}
int main()
{
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int t;
f >> t;
for( ; t > 0; --t){
solve(f, g);
}
return 0;
}