Cod sursa(job #3187089)
| Utilizator | Data | 27 decembrie 2023 14:57:54 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.75 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void eu(long long a, long long b, long long &c, long long &x, long long &y)
{
if(b==0)
{
c=a;
x=1;
y=0;
}
else
{
long long x1=0, y1=0;
eu(b,a%b, c, x1, y1);
x=y1;
y=x1-(a/b)*y1;
}
}
long long a,b, c,x,y,d,n;
int main()
{
fin>>n;
for(int i=1;i<=n;++i)
{
fin>>a>>b>>c;
x=0;
y=0;
eu(a,b,d,x,y);
if(c%d==0)
{
x=x*c/d;
y=y*c/d;
fout<<x<<" "<<y<<'\n';
}
else
fout<<"0 0\n";
}
return 0;
}
