Definitions. Let $n$ be a natural number and $S$ be a subset of distinct natural numbers all less than $n$, and mutually co-prime. Then find the maximum sum the set $S$ can have.
Example. Let $n=10$, then the maximum sum $S$ can have is $30$ corresponding to $S=\{1,5,7,8,9\}$.
What I tried. I tried to implement the following greedy algorithm.
- First I divide primes $\le n$ into $3$ lists: $list_1$ containing primes $\le \lfloor \sqrt{n} \rfloor$, $\; list_2$ containing primes in range $\big( \lfloor \sqrt(n) \rfloor,\lfloor \frac{n}{2} \rfloor \big )$ and finally $list_3$ containing prime in the range $\big[\lfloor \frac{n}{2} \rfloor+1,n \big ]$.
- Next I define a function $largest(a,b,n)$, which returns the largest number of the form $a*b^{r}$ less than equal to $n$.
- If there exist two numbers $l_1 \in list_1$ and $l_2 \in list_2$ such that $diff = largest(l_2,l_1,n)-( largest(1,l_1,n) + l_2 ) > 0$, I chose the pair $(l_1,l_2)$ such that $diff$ is maximised. I delete $l_1$ from $list_1$, $l_2$ from $list_2$ and append $largest(l_2,l_1,n)$ in $list_2$ and repeat step $3$. If no such pair $(l_1,l_2)$ exists such that $diff>0$, I go to step $4$.
- I don't change anything in $list_3$.
- In the end $ \{1\} \cup \{ l_1^r \; | \;l_1 \; \in list_1 \text{ and } largest(1,l_1,n)=r \} \cup list_2 \cup list_3$ is my desired set $S$ and I report the sum of it's elements.
Running example of my algorithm. If $n=30$,
#list_1 = {2,3,5}
#list_2 = {7,11,13}
#list_3 = {17,19,23,29}
#The first time step 3 is evaluated I get l_1 = 2 and l_2 = 7 ..
#.. as diff = ( 28 - ( 16 + 7 ) ) = 5 > 0 and diff is maximised
# so I delete 2 from list_1 and 7 from list_2 and append 28 in list_2
#When step 3 is evaluated again no such pair (l_1,l_2) is found
#So our desired list becomes S={1,27,25,11,13,28,17,19,23,29} with sum 193.
But my algorithm only seems to give correct for few simple cases only. Plus I am not able to prove/disprove or modify any of my assumptions .Now I am hopelessly stuck at the problem and I am not making any progress. But I still believe that some greedy algorithm is at work here.
PS: The question is from project Euler max-sum co-prime set. I would really appreciate just some hint or new direction to think.