Cod sursa(job #2944742)

Utilizator DenisONIcBanu Denis Andrei DenisONIc Data 22 noiembrie 2022 21:55:38
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.95 kb
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.first << ' ' << p.second << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define fi first
#define se second
#define NMAX 500005
const long double PI = acos(-1);

// Finds x and y s.t. ax + by = d where d is the returned value.
// If you need ax + by = c and c % d == 0 then x = x * (c/d) and y = y * (c/d)
// x and y can varry in the following way:
// x += k * (b/d) where d is gcd(a,b)
// y -= k * (a/d)
int gcd_extended(int a,int b,int &x,int &y)
{
  if (b==0)
  {
    x = 1; y = 0;
    return a;
  }
  else
  {
    int x0,y0,d;
    d = gcd_extended(b,a%b,x0,y0);
    x = y0;
    y = x0 - (a/b) * y0;
    return d;
  }
}

int main(){
  ios::sync_with_stdio(false);
  freopen("euclid3.in","r",stdin);
  freopen("euclid3.out","w",stdout);

  int t;
  scanf("%d", &t);
  while (t--){
    int a,b,c;
    scanf("%d%d%d", &a, &b, &c);
    int x, y;
    int d = gcd_extended(a,b,x,y);
    if (c%d!=0)
      cout<<"0 0\n";
    else
      cout<<x*(c/d)<<' '<<y*(c/d)<<'\n';
  }

  return 0;
}