Maximum LCM of Adjacent Pair
Coding Problem Keys
Maximum LCM of Adjacent Pair
Problem Statement
An array of N integers is passed as the input to the program. The program must print the maximum LCM value of two adjacent integers (among the N integers).
Input Format
The first line contains the value of N.The second line contains the N integers separated by space(s).
Output Format
The first line contains the two integers separated by space.Boundary Condition(s)
1 <= N <= 100000Example Input/Output 1
Input
424 12 50 10
Output
300
Example Input/Output 2
Input
615 25 35 70 100 70
Output
700Max Execution Time Limit: 3000 millisecs
Solution
Programming Language: Python 3 Language
def gcd(a,b):
if a==0:
return b
return gcd(b%a,a)
def lcm(a,b):
return (a//gcd(a,b))*b
n=int(input())
l=list(map(int,input().split()))
k=[]
for i in range(n-1):
d=lcm(l[i],l[i+1])
k.append(d)
print(max(k))
# Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments