Hints:
Approach: Since the task is to maximize the LCM, so if all three numbers don’t have any common factor then the LCM will be the product of those three numbers and that will be maximum.
Solution in C++:
- If n is odd then the answer will be n, n-1, n-2.
- If n is even,
- If gcd of n and n-3 is 1 then answer will be n, n-1, n-3.
- Otherwise, n-1, n-2, n-3 will be required answer.
- ///**********ALLAH IS ALMIGHTY************///
- ///AH Tonmoy
- ///Department of CSE,23rd Batch
- ///Islamic University,Bangladesh
- #include <bits/stdc++.h>
- using namespace std;
- void mlcm(long long int n)
- { if (n % 2 != 0)
- cout << n*(n - 1)*(n - 2);
- else if (__gcd(n, (n - 3)) == 1)
- cout << n*(n - 1)*(n - 3);
- else
- cout <<(n-1)*(n - 2)*(n - 3);
- }
- int main()
- {
- long long int n;
- cin>>n;
- if(n<3)
- cout<<n<<endl;
- else
- mlcm(n);
- return 0;
- }
No comments