Given a number N.Find the maximum possible LCM that can be attained by any three numbers less than or equal to N.
Note- LCM stands for Lowest Common Multiple. Also, Numbers can be repeated.
Example 1:
Input:
N=9
Output:
504
Explanation:
504 is the maximum LCM that can be attained
by any triplet of numbers less than or equal 9.
The triplet which has this LCM is {7,8,9}.
Example 2:
Input:
N=7
Output:
210
Explanation:
210 is the maximum LCM that can be attained
by any triplet of numbers less than or equal 7.
The triplet which has this LCM is {5,6,7}.
Your Task:
You don't need to read input or print anything. Your task is to complete the function lcmTriplets() that takes a number N as input parameter and returns the maximum LCM that can be attained by any three numbers less than or equal to N.
Expected Time Complexity:O(logN)
Expected Auxillary Space:O(logN)
Constraints:
1<=N<=10^{6}

Difficulty: MEDIUM
Tags: Mathematics
Expected Time Complexity: O(logN)
Expected Auxiliary Space: O(logN)

Starter code:
#User function Template for python3



class Solution:

    def lcmTriplets(self,N):

        #code here

Solutions:
class Solution:

	def lcmTriplets(self, N):
		if N == 2:
			return 2
		if N % 2 == 0 and N % 3 == 0 and ((N - 3) % 3 == 0):
			return (N - 1) * (N - 2) * (N - 3)
		if N % 2 == 0:
			return N * (N - 1) * (N - 3)
		else:
			return N * (N - 1) * (N - 2)


class Solution:

	def lcmTriplets(self, N):
		if N < 3:
			ans = N
		elif N % 2 == 0:
			if self.gcd(N, N - 3) == 1:
				ans = N * (N - 1) * (N - 3)
			else:
				ans = (N - 1) * (N - 2) * (N - 3)
		else:
			ans = N * (N - 1) * (N - 2)
		return ans

	def gcd(self, a, b):
		maxm = max(a, b)
		minm = min(a, b)
		g = minm
		if minm == 0:
			g = maxm
		else:
			while maxm % minm != 0:
				tmp = maxm
				maxm = minm
				minm = tmp % minm
			g = minm
		return g


import numpy as np

class Solution:

	def fgg(a, b, c):
		a = a * b // math.gcd(a, b)
		a = a * c // math.gcd(a, c)
		return a

	def lcmTriplets(self, n):
		if n == 1:
			return 1
		if n % 2 != 0:
			a = n
			b = n - 1
			c = n - 2
			a = a * b // math.gcd(a, b)
			a = a * c // math.gcd(a, c)
			return abs(a)
		elif n % 2 == 0 and math.gcd(n, n - 3) == 1:
			a = n
			b = n - 1
			c = n - 3
			a = a * b // math.gcd(a, b)
			a = a * c // math.gcd(a, c)
			return abs(a)
		else:
			a = n - 1
			b = n - 2
			c = n - 3
			a = a * b // math.gcd(a, b)
			a = a * c // math.gcd(a, c)
			return abs(a)


import math

class Solution:

	def lcmTriplets(self, n):
		if n == 1:
			return 1
		if n % 2 != 0:
			ans = abs(n * (n - 1) * (n - 2))
		elif math.gcd(n, n - 3) == 1:
			ans = abs(n * (n - 1) * (n - 3))
		else:
			ans = abs((n - 1) * (n - 2) * (n - 3))
		return ans


from math import gcd

class Solution:

	def lcmTriplets(self, n):
		if n == 1:
			return 1
		if n == 2:
			return 2
		if n == 3:
			return 6
		if n & 1:
			return n * (n - 1) * (n - 2)
		elif n % 2 == 0 and n % 3 == 0:
			return (n - 1) * (n - 2) * (n - 3)
		else:
			return n * (n - 1) * (n - 3)


class Solution:

	def lcmTriplets(self, n):
		if n <= 2:
			return n
		elif n % 2 == 0:
			if n % 3 == 0:
				return (n - 1) * (n - 2) * (n - 3)
			else:
				return n * (n - 1) * (n - 3)
		else:
			return n * (n - 1) * (n - 2)


class Solution:

	def lcmTriplets(self, N):
		if N <= 2:
			return N
		if N & 1:
			return N * (N - 1) * (N - 2)
		else:
			res = (N - 1) * (N - 2) * (N - 3)
			if math.gcd(N, N - 3) == 1:
				res = max(res, N * (N - 1) * (N - 3))
			return res


class Solution:

	def lcmTriplets(self, N):
		if N == 1:
			return 1
		elif N == 2:
			return 2
		elif N % 2 != 0:
			return N * (N - 1) * (N - 2)
		elif N % 6 == 0:
			return (N - 1) * (N - 2) * (N - 3)
		else:
			return N * (N - 1) * (N - 3)


import numpy as np
from itertools import permutations
from math import gcd

class Solution:

	def lcmTriplets(self, N):
		triplet = [N]
		if N < 3:
			return N
		if N % 2 == 0:
			if gcd(N, N - 3) == 1:
				triplet = [N, N - 1, N - 3]
			else:
				triplet = [N - 1, N - 2, N - 3]
		else:
			triplet = [N, N - 1, N - 2]
		return triplet[0] * triplet[1] * triplet[2]


class Solution:

	def lcmTriplets(self, N):
		import math
		if N == 2:
			return 2
		elif N == 1:
			return 1
		if N % 2 != 0:
			return (N - 1) * N * (N - 2)
		elif math.gcd(N, N - 3) == 1:
			return (N - 1) * (N - 3) * N
		else:
			return (N - 1) * (N - 2) * (N - 3)


import math

class Solution:

	def lcmTriplets(self, N):
		n = N
		largest = 1
		if n >= 2:
			if n % 2 != 0:
				lcm = abs((n - 2) * (n - 1)) // math.gcd(n - 2, n - 1)
				lcm = abs(lcm * n) // math.gcd(lcm, n)
				largest = lcm
			elif math.gcd(n, n - 3) == 1:
				lcm = abs((n - 3) * (n - 1)) // math.gcd(n - 3, n - 1)
				lcm = abs(lcm * n) // math.gcd(lcm, n)
				largest = lcm
			elif n != 1:
				lcm = abs((n - 1) * (n - 2)) // math.gcd(n - 1, n - 2)
				lcm = abs(lcm * (n - 3)) // math.gcd(lcm, n - 3)
				largest = lcm
		elif n == 1:
			largest = 1
		return largest


class Solution:

	def lcmTriplets(self, N):
		table = {1: 1, 2: 2, 3: 6, 4: 12, 5: 60, 6: 60}
		if N in table:
			return table[N]
		if N % 2 == 1:
			return N * (N - 1) * (N - 2)
		if N % 3 != 0:
			return N * (N - 1) * (N - 3)
		return (N - 1) * (N - 2) * (N - 3)


import math

class Solution:

	def lcmTriplets(self, n):
		if n == 1 or n == 2:
			return n
		ans = 0
		if n % 2 != 0:
			ans = n * (n - 1) * (n - 2)
		else:
			if math.gcd(n, n - 3) == 1:
				ans = n * (n - 1) * (n - 3)
			if math.gcd(n - 1, n - 2) == 1 and math.gcd(n - 2, n - 3) == 1:
				ans = max(ans, (n - 2) * (n - 1) * (n - 3))
		return ans


class Solution:

	def hcf(self, a, b):
		if b == 1:
			return 1
		if a % b == 0:
			return b
		return self.hcf(b, a % b)

	def lcmTriplets(self, N):
		if N < 3:
			return N
		if N % 2 == 1:
			return N * (N - 1) * (N - 2)
		res = (N - 1) * (N - 2) * (N - 3)
		tmp = N * (N - 1)
		for i in range(N - 3, (N - 2) // 2, -2):
			if self.hcf(N, i) == 1 and self.hcf(N - 1, i) == 1:
				return max(res, tmp * i)
		return max(res, tmp * (N - 2) // 2)


class Solution:

	def lcmTriplets(self, N):
		if N <= 3 or N % 2 != 0:
			return max(N, N * (N - 1), N * (N - 1) * (N - 2))
		else:
			return (N - 1) * (N - 2) * (N - 3) if N % 3 == 0 else N * (N - 1) * (N - 3)


class Solution:

	def lcmTriplets(self, n):
		if N <= 2:
			return N
		if N & 1 == 1:
			return N * (N - 1) * (N - 2)
		if N % 3 == 0:
			return (N - 2) * (N - 1) * (N - 3)
		return N * (N - 1) * (N - 3)


class Solution:

	def lcmTriplets(self, N):
		p = N * (N - 1) * (N - 2)
		q = (N - 1) * (N - 2) * (N - 3)
		if N == 1 or N == 2:
			return N
		if N % 2 != 0:
			return p
		if N % 3 == 0:
			return q
		return max(N * (N - 1) * (N - 3), q)


def hcf(a, b):
	r = a % b
	if r == 0:
		return b
	else:
		return hcf(b, r)

class Solution:

	def lcmTriplets(self, N):
		if N == 1 or N == 2:
			return N
		elif N == 3:
			return N * 2
		elif N % 2 == 1:
			return N * (N - 1) * (N - 2)
		elif N % 3 == 0:
			return (N - 1) * (N - 2) * (N - 3)
		else:
			return N * (N - 1) * (N - 3)