# Cod sursa(job #2749117)

Utilizator Data 5 mai 2021 01:31:09 Algoritmul lui Euclid 100 cpp-64 done Arhiva educationala 1.63 kb
``````#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <array>
#include <fstream>

using namespace std;

void printVector(vector<int64_t> v) {
for (auto& el : v) {
cout << el << " ";
}
cout << "\n";
}

int64_t maxim = v[0], indice = 0;
for (int i = 0; i < v.size() - 1; i++) {
if (v[i] < v[i + 1] && maxim < v[i + 1]) {
maxim = v[i + 1];
indice = i + 1;

}
else if (v[i] > v[i + 1] && maxim < v[i]) {
maxim = v[i];
indice = i;
}
}

return maxim;
}

int maxim(vector<int64_t> v) {
int64_t m = v[0];
for (auto el : v) {
m = max(el, m);
}
return m;
}

vector<int64_t> generateRandomVector(int64_t n, int64_t left, int64_t right) {
srand(time(NULL));

int64_t space = right - left;
vector <int64_t> v;
for (int i = 0; i < n; i++) {
int64_t el = rand() % space + left;
v.push_back(el);
}
return v;
}

int64_t maxVector(vector<int64_t> a) {
int64_t m = a[0];
for (int i = 1; i < a.size(); i++) {
m = max(a[i], m);
}
return m;
}

int64_t maximIndiceVector(vector<int64_t> a) {
int64_t m = a[0];
int indice = 0;
for (int i = 1; i < a.size(); i++) {
if (a[i] > m) {
m = a[i];
indice = i;
}
}
return indice;
}

int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}

int main()
{
ifstream fin("euclid2.in");
ofstream fout("euclid2.out");
int64_t nr1, nr2, rest, n;
fin >> n;
for (int i = 0; i < n; i++) {
fin >> nr1 >> nr2;
while (nr2 != 0) {
rest = nr1 % nr2;
nr1 = nr2;
nr2 = rest;
}
fout << nr1 << "\n";
}
}
``````