Lowest Common Multiple (LCM) You are given an array of positive integers, arr, of size array length. You are asked to build set S which consists of the LCM of every pair of adjacent elements in arr. Your task is to find the largest element in set S. For example, for the array (1, 2, 3, 4), set S ( Icm(1,2), Icm(2,3), Icm(3,4)} = (2, 6, 12). The largest element is 12

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question
VelTech Codeathon Jan Finals
Test will be
Lowest Common Multiple (LCM)
You are given an array of positive integers, arr, of size array length. You are asked to build set S which
consists of the LCM of every pair of adjacent elements in arr. Your task is to find the largest element in set S
For example, for the array (1, 2, 3, 4), set S = { Icm(1,2), Icrm(2,3), Icrm(3,4) } = (2, 6, 12). The largest element is
Fill you
12
Notes
The array contains only positive integers.
Adjacent elements may NOT be circular, ie. they may not wrap around the end of the array
Definition of LCM
A multiple of a number, num, is a number that can be divided by num. For example, the multiples of 5 are 5, 10,
15, 20, 25, and so on, The lowest common multiple (LCM) of two numbers, a and b, is the smallest positive
number that is a multiple of both a and b
Example 1
Input
4
1324
Output
9.
Explanation
set S= (lcm(1, 3), Icm(3, 2), Icm(2, 4) ) = (3, 6, 4)
Largest element 6
Example 2
Pro
Input
7329 12
Output
36
Explanation
set 5= ( Iom(7, 3), fom(3, 2), lcm(2, 9), Icm(9, 12) } = (21, 6, 18, 36)
Largest element = 36
Input format
The first line of input denotes the size of an aray
The next lines contain the space-separated integers denoting the value of the array
Output format
The outout contains an integer denoting the largest elemert in set S at sbecified in the piabiem statenet
fode consraints
Transcribed Image Text:VelTech Codeathon Jan Finals Test will be Lowest Common Multiple (LCM) You are given an array of positive integers, arr, of size array length. You are asked to build set S which consists of the LCM of every pair of adjacent elements in arr. Your task is to find the largest element in set S For example, for the array (1, 2, 3, 4), set S = { Icm(1,2), Icrm(2,3), Icrm(3,4) } = (2, 6, 12). The largest element is Fill you 12 Notes The array contains only positive integers. Adjacent elements may NOT be circular, ie. they may not wrap around the end of the array Definition of LCM A multiple of a number, num, is a number that can be divided by num. For example, the multiples of 5 are 5, 10, 15, 20, 25, and so on, The lowest common multiple (LCM) of two numbers, a and b, is the smallest positive number that is a multiple of both a and b Example 1 Input 4 1324 Output 9. Explanation set S= (lcm(1, 3), Icm(3, 2), Icm(2, 4) ) = (3, 6, 4) Largest element 6 Example 2 Pro Input 7329 12 Output 36 Explanation set 5= ( Iom(7, 3), fom(3, 2), lcm(2, 9), Icm(9, 12) } = (21, 6, 18, 36) Largest element = 36 Input format The first line of input denotes the size of an aray The next lines contain the space-separated integers denoting the value of the array Output format The outout contains an integer denoting the largest elemert in set S at sbecified in the piabiem statenet fode consraints
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT