Cod sursa(job #3326985)

Utilizator radu._.21Radu Pelea radu._.21 Data 1 decembrie 2025 17:53:06
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");

int gcd(int a, int b, int &x, int &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }

  int x0, y0, d;

  d = gcd(b, a % b, x0, y0);
  x = y0;
  y = x0 - (a / b) * y0;
  return d;
}

void solve() {
  int a, b, c, x, y;
  f >> a >> b >> c;
  int d = gcd(a, b, x, y);
  if (c % d)
    g << 0 << " " << 0;
  else
    g << x * (c / d) << " " << y * (c / d);
}

int main() {
  int cases;
  f >> cases;
  while (cases--) {
    solve();
    g << "\n";
  }
  return 0;
}