maximize the sum of numbers such that all of them are coprime

316 Views Asked by At

Suppose we have numbers from $2$ to $n$ (inclusive). We want to choose numbers such that all of them are coprime and give the maximum sum.

For example, if $n=10$, then we choose $9,8,7,5$ and the sum is $29$. Note that we didn't choose $10,9,7$ since the sum is smaller than the former. I did this by trial and error. Is there an algorithm which gives me the numbers?

1

There are 1 best solutions below

0
On

Take all the primes from $2$ to $n$. The basic idea now is to substitute two numbers $a$ and $b$ by their product, provided that $ab\leq n$. Then, the sum increases $ab-a-b=(a-1)(b-1)+1$, formula which is crearly increasing respect to $a$ and $b$. So pick $n$. If it is not yet in the set and it can be expressed as a product of two members of the set, delete these two numbers and put $n$. Repeat with $n-1$, etc.

When you finish, begin again from $n$ to $2$, and repeat this until you can't make any more substitutions.

Warning: I have made no proofs, so I'm not completely sure that this process actually gives the maximum sum.