19
1
Landau's function \$g(n)\$ (OEIS A000793) gives the maximum order of an element of the symmetric group \$S_n\$. Here, the order of a permutation \$\pi\$ is the smallest positive integer \$k\$ such that \$\pi^k\$ is the identity - which is equal to the least common multiple of the lengths of the cycles in the permutation's cycle decomposition. For example, \$g(14) = 84\$ which is achieved for example by (1,2,3)(4,5,6,7)(8,9,10,11,12,13,14).
Therefore, \$g(n)\$ is also equal to the maximum value of \$\operatorname{lcm}(a_1, \ldots, a_k)\$ where \$a_1 + \cdots + a_k = n\$ with \$a_1, \ldots, a_k\$ positive integers.
Problem
Write a function or program that calculates Landau's function.
Input
A positive integer \$n\$.
Output
\$g(n)\$, the maximum order of an element of the symmetric group \$S_n\$.
Examples
n g(n)
1 1
2 2
3 3
4 4
5 6
6 6
7 12
8 15
9 20
10 30
11 30
12 60
13 60
14 84
15 105
16 140
17 210
18 210
19 420
20 420
Score
This is code-golf: Shortest program in bytes wins. (Nevertheless, shortest implementations in multiple languages are welcome.)
Note that there are no requirements imposed on run-time; therefore, your implementation does not necessarily need to be able to generate all the above example results in any reasonable time.
Standard loopholes are forbidden.
Not that familiar with the language - but
Max[Apply@LCM/@IntegerPartitions@#]&
seems to work for me and would give 36 bytes if it's correct. – Daniel Schepler – 2019-08-30T17:22:37.4072
@DanielSchepler yes, super! Why don't you propose it as a separate solution? You can even do
– Roman – 2019-08-30T17:39:39.870Max[LCM@@@IntegerPartitions@#]&
for 31 bytes, because@@@
doesApply
at level 1.