Cod sursa(job #2429800)

Utilizator stefanut999Paul Colta stefanut999 Data 11 iunie 2019 10:35:51
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <iostream>
#include <cstring>
#include <stack>
#include <bits/stdc++.h>
#include <vector>
#define rep(a,b,c) for(a = b; a <= c; ++a)
#define nmax 1001
#define pob pop_back
#define pof pop_front
#define pub push_back
#define ll long long int
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

int euclid(ll a, ll b, ll &x, ll &y, ll &d)
{
  if(!b)
  {
    x = 1;
    y = 0;
    d = a;
  }
  else
    {
      ll x0, y0;
      euclid(b, a % b, x0, y0, d);
      x = y0;
      y = x0 - a / b * y0;
    }
}

ll t, a, i, b, c, x, y, d;

int main()
{
  fin >> t;
  rep(i, 1, t)
    {
      fin >> a >> b >> c;
      euclid(a, b, x, y, d);
      if(c % d != 0)
        {
          fout << 0<<" "<<0;
        }
      else
        fout << x * c / d<<' '<< y * c / d;
      fout << '\n';
    }

  return 0;
}