The least common multiple (LCM) of a set of numbers A
is the smallest integer b
such that b/a
is an integer for all integers a
in A
. This definition can be extended to rational numbers!
Task
Find the smallest positive rational b
such that b/a
is an integer for all rationals a
in the input.
Rules
- Standard loopholes are forbidden.
- You may take numerators and denominators separately in the input, but may not take doubles, floats, etc.
- The input may not be fully reduced.
- You may take integer inputs as rationals with denominator of
1
. - Submissions that would feed rational numbers to an LCM/GCD builtin are allowed, but non-competing.
Test Cases
In: 3
Out: 3
In: 1/17
Out: 1/17
In: 1/2, 3/4
Out: 3/2
In: 1/3, 2/8
Out: 1
In: 1/4, 3
Out: 3
In: 2/5, 3
Out: 6
In: 1/2, 3/4, 5/6, 7/8
Out: 105/2
This is code-golf, so submissions using the fewest bytes win!
LCM[numerators]/GCD[denominators]
may not work when the input contains a non-reduced rational number. e.g.1/3, 2/8
. \$\endgroup\$