Given a list of $N$ digits. I have to create groups of these digits which represent a single number such that their $GCD$ is maximized.Min and max number of groups that are allowed is given by user. The number of digits in a number can't exceed $6$ and the maximum number of digits in a number is given by user.
I thought of making every group with maximum number of digits allowed and calculating their $GCD$ but it's not optimal. Is there any efficient and optimal way to do this ?
Eg- Suppose the list is - $4,5,3,4,5,6$ and maximum no. of digits are = $3$ so the numbers can be
- $453,456$ , $gcd(453,456)$
- $4,53,456$ , $gcd(4,53,456)$ and so on.