Cod sursa(job #3271428)

Utilizator andrei.nNemtisor Andrei andrei.n Data 26 ianuarie 2025 11:07:53
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.12 kb
#include <bits/stdc++.h>

using namespace std;

struct vec2
{
    int x,y;
    vec2(int _x = 0, int _y = 0) : x(_x), y(_y) {}
};

#define DEFINE_ADD_SUBSTR(op)\
vec2 operator op(const vec2 &a, const vec2 &b){\
    return vec2(a.x op b.x, a.y op b.y);\
}

#define DEFINE_MULT_DIV(op)\
vec2 operator op(const vec2 &a, const int &b){\
    return vec2(a.x op b, a.y op b);\
}

DEFINE_ADD_SUBSTR(+)
DEFINE_ADD_SUBSTR(-)
DEFINE_MULT_DIV(*)
DEFINE_MULT_DIV(/)

signed main()
{
    ifstream fin ("euclid3.in");
    ofstream fout ("euclid3.out");
    ios::sync_with_stdio(false); fin.tie(0); fout.tie(0);
    int T; fin>>T; while(T--)
    {
        int a,b,c; fin>>a>>b>>c;
        int d = __gcd(a,b), r;
        if(c%d)
        {
            fout<<"0 0\n";
            continue;
        }
        a /= d; b /= d; c /= d;
        vec2 va(1,0), vb(0,1), vr;
        while(b != 0)
        {
            vr = va - vb * (a / b);
            va = vb;
            vb = vr;
            r = a%b;
            a = b;
            b = r;
        }
        fout<<va.x * c<<' '<<va.y * c<<'\n';
    }
    return 0;
}