Record a thinking question of lcm, gcd, thank my friend for your help!

Gives you an integer n(2<=n<=10^9)

Let you find two numbers a, b (1<=a,b<=n)

Make the value of lcm(a,b)-gcd(a,b) the largest possible.

 

trick: the largest lcm(a,b) is lcm(n,n-1), the smallest gcd(a,b)=gcd(n,n-1)=1

So the answer is n*(n-1)-1. Note that the answer is out of the int range. Use longlong to calculate and save.

Guess you like

Origin blog.csdn.net/hbhhhxs/article/details/105188010