Cod sursa(job #2494580)
| Utilizator | Data | 18 noiembrie 2019 09:45:35 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("euclid2.in");
ofstream fout("euclid2.out");
void gcdextended(int a, int b, int &d, int &x, int &y)
{
if(b==0){
x=1, y=0;
d=a;
}
else{
int x1, y1;
gcdextended(b, a%b, d, x1, y1);
x=y1;
y=x1-(a/b)*y1;
}
}
int main()
{
int a, b, n;
fin>>n;
while(n--)
{
fin>>a>>b;
int x=0, y=0, d;
gcdextended(a, b, d, x, y);
fout<<d<<"\n";
}
return 0;
}
