Cod sursa(job #3135043)
| Utilizator | Data | 1 iunie 2023 17:02:47 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.7 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int d,x,y;
void euclid3(int a, int b, int x1, int y1, int x2, int y2)
{
if(!b)
{
d = a;
x = x1;
y = y1;
}
else
{
euclid3(b, a % b, x2, y2, x1 - a / b * x2, y1 - a / b * y2);
}
}
int main()
{
int n;
fin>>n;
while(n)
{
int a,b,c;
fin>>a>>b>>c;
euclid3(a, b, 1, 0, 0, 1);
if(!(c % d))
{
x *= c/d;
y *= c/d;
}
else
{
x = 0;
y = 0;
}
fout << x <<" "<< y << '\n';
n--;
}
return 0;
}