# Table of numbers and their divisors

I want to create a table of random numbers and their divisors. The random numbers are given by

TableForm[{{Subscript[m, 1] = RandomInteger[{2, 50}],
Subscript[n, 1] = RandomInteger[{2, 50}]},
{Subscript[m, 2] = RandomInteger[{2, 50}],
Subscript[n, 2] = RandomInteger[{2, 50}]},
{Subscript[m, 3] = RandomInteger[{2, 50}],
Subscript[n, 3] = RandomInteger[{2, 50}]}},
TableHeadings -> {{"1", "2", "3"}, {"m", "n"}},
TableAlignments -> Center]


So far so good. A neat table with delimiters for the headings. But when I try to add the divisors it all goes wrong:

TableForm[{{Subscript[m, 1] = RandomInteger[{2, 50}],
Subscript[n, 1] = RandomInteger[{2, 50}],
Divisors[Subscript[m, 1]],
Divisors[Subscript[n, 1]]}, {Subscript[m, 2] =
RandomInteger[{2, 50}],
Subscript[n, 2] = RandomInteger[{2, 50}],
Divisors[Subscript[m, 2]], Divisors[Subscript[n, 2]]},
{Subscript[m, 3] = RandomInteger[{2, 50}],
Subscript[n, 3] = RandomInteger[{2, 50}],
Divisors[Subscript[m, 3]], Divisors[Subscript[n, 3]]}},
TableHeadings -> {{"1", "2", "3"}, {"m", "n", "divisors[m]",
"divisors[n]"}},
TableAlignments -> Center]


I want the heading delimiters to remain, but they disappear; and I'd like the divisors to appear in a comma-delimited horizontal list (for example Divisors would produce 1,2,4 rather than a vertical list.

SeedRandom
table = RandomInteger[{2, 50}, {3, 2}];
TableForm[Join[table, Map[Row[Divisors[#], " "] &, table, {-1}], 2],
TableHeadings -> {{"1", "2", "3"}, {"m", "n", "divisors[m]", "divisors[n]"}},
TableAlignments -> Center] • Many thanks @kglr. I'm struggling to incorporate this solution into other forms of table (mainly because I don't understand what you did!) I'd also like to create a table that lists n from 1 to 25 in one column, and Divisors[n] in the second column, formatted as you did in your answer above. Mar 8, 2019 at 11:10
• @Richard, table is a 3X2 matrix of numbers as in your first example. Map[Divisors, table, {-1}] gives the divisors of each entry in that matrix. I wrapped each list of divisors with Row[..., " "] so that each divisor list is displayed horizontally. A simpler form using the options TableDirections is TableForm[Join[table, Map[Divisors, table, {-1}], 2], TableHeadings -> {{"1", "2", "3"}, {"m", "n", "divisors[m]", "divisors[n]"}, None}, TableAlignments -> Center, TableDirections -> {Column, Row, Row}] but, due to a glitch/bug it doesn't display the dividers.
– kglr
Mar 8, 2019 at 11:23
• ... so i had to use Row around the inner lists. The example in your comment can be done using TableForm[Transpose[{Range, Row[Divisors[#]] & /@ Range}], TableHeadings -> {Automatic, {"n", "divisors[n]"}}, TableAlignments -> Center].
– kglr
Mar 8, 2019 at 11:24