I'm working on a programming problem here: https://codeforces.com/problemset/problem/235/A
Find an algorithm to solve the question:
Given $1\leq n\leq 10^6,$ return the largest value of $\operatorname{lcm}(a,b,c)$ where $a,b,c$ are integers between $1$ and $n$ inclusive.
It is not a live competition, and I have already read a solution to it, but I would like to know whether my approach works. Also, although the problem is programming, I thought that the actual solution was inherently math, so it was more reasonable to post it here, rather than, say, stackoverflow.
After doing some research, I learned that the inequality
$$\gcd(a_{1}, a_{2}, \ldots, a_{n}) \cdot \text{lcm}(a_{1}, a_{2}, \ldots, a_{n}) \leq \prod_{i=1}^{n}a_{i}$$
holds. So this motivated me to write the following algorithm:
Iterate $G = \text{gcd}(a_{1}, a_{2}, \ldots, a_{n})$ from $1$ to $n$. These are the only possible values that $G$ can take.
For every $G$, choose three numbers that are the largest multiples of $G$. For example, if $G = 2$ and $n = 9$, then we would choose $8, 6, 2$.
Compute the lcm for that gcd. This is a maximal value of the LCM for that gcd.
Is my approach correct?
Thanks