Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 957229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:40:08+00:00 2026-05-16T00:40:08+00:00

I am looking for an optimum way to create a table from n elements

  • 0

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 / rows becomes as close to 1 as possible.

Of course if n is a square number it is easy since then

cols = rows = sqrt( n );

If n is a prime number it is also clear that there will be empty cells, so my current way to handle this is:

rows = floor( sqrt(n) );
cols = ceil( n / rows  );

For all other cases my plan is to get the prime factors of n and then search all possible permutations for those whose combination has proportions closest to 1.

So my question is: is there is a better way to do this? Or is there at least a way not having to test every possible combination of the prime factors?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:40:09+00:00Added an answer on May 16, 2026 at 12:40 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking for a control that allows to select one text value at a time
I'm looking for any advice on what's the optimum way of inserting a large
Looking for a better way of extracting a number from the last line in
Looking for easy way to support retina displays. It occurred to me that if
I am looking for an optimum sleep value to receive data from a non-blocking
Looking to create a vertical button group that looks very similar to Twitters own
Looking at posts like this and others, it seems that the correct way to
Looking for a way of getting the path from an URL in PHP: I
Looking to create this: What would be the best way to achieve it? IT
Looking for a way to get path of file (and then process it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.