Our task is to find maximum $l$ where $ l \ge 0 $ and $ l\le k$ such that $$\gcd(a_0 ,a_1,...,a_n,l)>1.$$
Solution to problem says that $l=k-(k\bmod g)$ so we can iterate through all divisors of $ \gcd(a0 ,a1 ,a2 ,.... ,an)$ and For each divisor, calculate the largest l such that $\gcd(a0, a1,a2,.... an)$ evenly divides $l$ , then choose the maximum among them.
HERE $a_0 ,a_1, ... ,a_n$ are numbers we already know.
I could not understand as how this solution is right ? can anyone explain it more clearly?
You need to find the largest integer less than or equal to $k$ that shares a prime divisor with the number $N$, where $N=\gcd(a_1,a_2\dots a_m)$.
So the numbers you have to consider are $p\lfloor\frac{l}{p}\rfloor$, where $p$ is a prime dividing $N$. The answer is the maximum of these numbers.