Cod sursa(job #2817499)

Utilizator victorzarzuZarzu Victor victorzarzu Data 13 decembrie 2021 18:52:57
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>
#define n_max 100001

using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int n;

int euclid(int a, int b, int &x, int &y)
{
  if(!b)
  {
    x = 1;
    y = 0;
    return a;
  }
  int x0, y0;
  int cmmdc = euclid(b, a % b, x0, y0);

  x = y0;
  y = x0 - y0 * (a / b);
  return cmmdc;
}

void solve(int a, int b, int c)
{
  int x, y;
  int cmmdc = euclid(a, b, x, y);
  if(c % cmmdc)
    g<<0<<" "<<0<<'\n';
  else
    g<<x * (c / cmmdc)<<" "<<y * (c / cmmdc)<<'\n';
}

void read()
{
  f>>n;
  int a, b, c;
  for(int i = 1;i <= n;++i)
    {
      f>>a>>b>>c;
      solve(a, b, c);
    }
}

int main()
{
  read();
  return 0;
}