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 4600380
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:40:33+00:00 2026-05-21T23:40:33+00:00

I have a number n , and I want to find three numbers whose

  • 0

I have a number n, and I want to find three numbers whose product is n but are as close to each other as possible. That is, if n = 12 then I’d like to get 3, 2, 2 as a result, as opposed to 6, 1, 2.

Another way to think of it is that if n is the volume of a cuboid then I want to find the lengths of the sides so as to make the cuboid as much like a cube as possible (that is, the lengths as similar as possible). These numbers must be integers.

I know there is unlikely to be a perfect solution to this, and I’m happy to use something which gives a good answer most of the time, but I just can’t think where to go with coming up with this algorithm. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 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-21T23:40:34+00:00Added an answer on May 21, 2026 at 11:40 pm

    Here’s my first algorithm sketch, granted that n is relatively small:

    • Compute the prime factors of n.
    • Pick out the three largest and assign them to f1, f2, f3. If there are less than three factors, assign 1.
    • Loop over remaining factors in decreasing order, multiply them into the currently smallest partition.

    Edit

    Let’s take n=60.

    Its prime factors are 5 3 2 2.

    Set f1=5, f2=3 and f3=2.

    The remaining 2 is multiplied to f3, because it is the smallest.

    We end up with 5 * 4 * 3 = 60.


    Edit

    This algorithm will not find optimum, notice btillys comment:

    Consider 17550 = 2 * 3 * 3 * 3 * 5 * 5
    * 13. Your algorithm would give 15, 30, 39 when the best is 25, 26, 27.


    Edit

    Ok, here’s my second algorithm sketch with a slightly better heuristic:

    • Set the list L to the prime factors of n.
    • Set r to the cube root of n.
    • Create the set of three factors F, initially set to 1.
    • Iterate over the prime factors in descending order:
      • Try to multiply the current factor L[i] with each of the factors in descending order.
        • If the result is less than r, perform the multiplication and move on to the next
          prime factor.
        • If not, try the next F. If out of Fs, multiply with the smallest one.

    This will work for the case of 17550:

    n=17550
    L=13,5,5,3,3,3,2
    r=25.98
    
    F = { 1, 1, 1 }
    

    Iteration 1:

    • F[0] * 13 is less than r, set F to {13,1,1}.

    Iteration 2:

    • F[0] * 5 = 65 is greated than r.
    • F[1] * 5 = 5 is less than r, set F to {13,5,1}.

    Iteration 3:

    • F[0] * 5 = 65 is greated than r.
    • F[1] * 5 = 25 is less than r, set F to {13,25,1}.

    Iteration 4:

    • F[0] * 3 = 39 is greated than r.
    • F[1] * 3 = 75 is greated than r.
    • F[2] * 3 = 3 is less than r, set F to {13,25,3}.

    Iteration 5:

    • F[0] * 3 = 39 is greated than r.
    • F[1] * 3 = 75 is greated than r.
    • F[2] * 3 = 9 is less than r, set F to {13,25,9}.

    Iteration 6:

    • F[0] * 3 = 39 is greated than r.
    • F[1] * 3 = 75 is greated than r.
    • F[2] * 3 = 27 is greater than r, but it is the smallest F we can get. Set F to {13,25,27}.

    Iteration 7:

    • F[0] * 2 = 26 is greated than r, but it is the smallest F we can get. Set F to {26,25,27}.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 1M numbers:N[], and 1 single number n, now I want to find
I have an integer column and I want to find numbers that start with
I have the code in which i want to find out the greatest number
I have some numbers stored in a std::vector<int> . I want to find which
I have a number of generated .sql files that I want to run in
I have a number of images and a CSV data file that I want
I have a list of incomplete ordered numbers. I want to find a particular
I have a phone number I want to match against a regular expression. The
I have the number 33 and want to split it in pieces of 10
I have a number (hex) and I want the one's complement of it. For

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.