maximum LCM

Revision en2, by TuHoangAnh, 2021-12-30 16:39:51

given an integer $$$n$$$, you have to find $$$a,b>0$$$ so that $$$a+b=n$$$ and $$$LCM(a,b)$$$ is maximum($$$LCM$$$ is the least common multiple of $$$a,b$$$).

printf the maximum $$$LCM(a,b)$$$

i have come up with a bruteforce solution. I will consider all pairs of $$$a,b$$$ that have sum equal to $$$n$$$. And calculate the value of

$$$LCM(a,b)=(a*b)/GCD(a,b)$$$. ($$$GCD$$$ is greatest common divisor).

But, this solution seems too slow when $$$n<=10^9$$$. Is there a better solution for this problem ?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English TuHoangAnh 2021-12-30 16:39:51 2 Tiny change: 'D(a,b)$. (GCD is greate' -> 'D(a,b)$. ($GCD$ is greate'
en1 English TuHoangAnh 2021-12-30 16:36:37 482 Initial revision (published)