What is the optimal way to solve the following optimization problem
Yes, there is a simple way to compute $F$.

Proposition: $F(a_1,a_2\ldots a_n)=\gcd (a_1,a_2\ldots a_n)$, where $\gcd$ is the greatest common divisor.

Proof: I will leave it as an exercise. Hint, the replacement of $a_j$ by $a_j-a_i$ whenever $a_i&lt;a_j$ is very powerful.

Here is a simple and efficient algorithm to compute $F(a_1,a_2\ldots a_n)$.


Let $r = a_1$.
Iterate $i$ through $2,3, \cdots, n$, setting $r$ to $\gcd(a_i, r)$. Here $\gcd(a_i,r)$ can be computed by any of your favorite GCD algorithms such as Euclidean algorithm or binary GCD algorithm.
return $r$.