Saturday, 2 July 2016

number theory - Is maximizing an LCM equivalent to minimizing a GCD?



I'm working on a programming problem here: https://codeforces.com/problemset/problem/235/A




Find an algorithm to solve the question:



Given 1n106, return the largest value of 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(a1,a2,,an)lcm(a1,a2,,an)ni=1ai



holds. So this motivated me to write the following algorithm:




  • Iterate G=gcd(a1,a2,,an) 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


Answer



The first key is:





Theorem 1: If a1,,ak are positive integers which are pair-wise relatively prime (that is, gcd(ai,aj)=1 when ij) we have that lcm(a1,,ak)=ki=1ai




The second key is:




Theorem 2: if a1,,ak are positive integers then there are pair-wise relatively prime integers a1,,ak with 1aiai for all i and ni=1ai=lcm(a1,,ak)=lcm(a1,,ak)


(You can actually get aiai.)





So the set of least common multiples of k numbers from 1 to n is the same as the set of products of k pairwise relatively prime numbers from 1 to n.



Then, in order to find the maximum LCM, we need to find the maximum product of three pairwise relatively prime numbers numbers.



When n is odd, n,n1, and n2 are pairwise relatively prime, so we get a least common multipe of n(n1)(n2) which is the maximum product of three numbers from 1 to n,, at least if n>2.



When n is even, but not divisible by 3, then n,n1 and n3 are pairwise relatively prime. This is because the only product of three different numbers from 1 to n is n(n1)(n2), but n and n2 are not relatively prime when n is even.



When n is even and divisible by 3, then we have that n1 is odd, so (n1)(n2)(n3) is a lest common multiple. On the other hand, any other product of three pairwise relatively prime integers with n involved is at most n(n1)(n5). But n(n5)<(n2)(n3) so n(n1)(n5)<(n1)(n2)(n3). So when n is divisible by 6, the maximal value is (n1)(n2)(n3).




You have to take care when n2. In those cases, multiple values can be equal to 1. . When n=2, you have a maximal LCM is 2. When n=1, the maximum LCM is 1.






Example of theorem 2: If a1=12,a2=45,a3=30, then we have:



a1=223150a2=203251a3=213151,

then we can take:



a1=22a2=32a3=51.



The ai are pairwise relatively prime and the LCM is the product which is 223251=180, and this is the least common multiple of the original triple 12,45,30.


No comments:

Post a Comment

real analysis - How to find limhrightarrow0fracsin(ha)h

How to find limh0sin(ha)h without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...