GCD algorithm is associative, which means that `GCD(a, b, c, d)`

is equivalent to `GCD(GCD(GCD(a, b), c), d)`

so we can just run it in a loop and apply to each consecutive pair. Return 1 if sequence is empty as every number is divisible by 1.

```
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
int gcd_of_all(const std::vector<int>& values)
{
if (values.empty())
return 1; // division by 1 does nothing
int result = values[0];
for (std::size_t i = 1; i < values.size(); ++i)
{
result = std::gcd(result, values[i]);
}
return result;
}
int main()
{
std::vector<int> v = { 10, 20, 30, 40 };
int gcd = gcd_of_all(v);
std::cout << "gcd: " << gcd << "\n";
for (int& elem : v)
elem /= gcd;
for (int elem : v)
std::cout << elem << " ";
}
```

**Additional**: the reason I used `std::size_t i = 1; i < values.size(); ++i`

instead of the usual `int i = 1;...`

is because if int is used, it triggers compilers warnings because `i < values.size()`

will be comparing numbers of different signess