I am looking for an optimum way to create a table from n elements so that ideally there are no empty cells, but at the same time the proportion of the table dimensions columns /
Instead of doing a prime factorization of n, start from the square root and find the next larger (or smaller -- makes no difference) factor. That pair of factors will the closest to the square root, and therefore the closest to a proportion of 1:1.