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

  • Home
  • SEARCH
  • 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 7841937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:12:22+00:00 2026-06-02T16:12:22+00:00

I need to sort a range of numbers. The numbers can be from 0

  • 0

I need to sort a range of numbers. The numbers can be from 0 to 1000. The user enters a range of numbers between 0 and 1000. So if they for example maybe enter 0 -> 500.

My goal would be to take all the numbers in the range given and output all the numbers in that range that have only 4 possible divisors (including 1 and itself.

I’m wondering if I should use an algorithm such as this one, or if I should check and int array that contains all the numbers from 1 – 1000 that are divisible by 4 (so the array doesn’t have 1-1000 it has the numbers in that range that would be divisible 4 times only. Would require manual work to add all the possible divisors to that array).

I’m looking to make it efficient just I’m not sure if using such an algorithm would be very fast for this.

  • 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-06-02T16:12:23+00:00Added an answer on June 2, 2026 at 4:12 pm

    You’re looking for a number that’s the product of two primes edit: or the cube of a prime. Since your numbers are small, you can just make a short table of the primes between 2 and 500. Then, starting with 2, multiply each prime by each of the primes above it until you’re over your upper limit.

    Edit: Is this homework? If it is, I’ve probably said too much already. If it isn’t, I can provide some code or pseudocode if my answer doesn’t make sense.

    Edit: Thanks, Daniel Fischer: I missed the cubes of primes. You can check for and include these in your outer loop. (Before you multiply a prime by each of those above it, see if its cube falls in in the desired range.)

    Generally:

    for ( p1 is a prime in your list, except for the last) {
        if p1 cubed is in your range, add it to the answer
        for (p2 is a prime in your list greater than p1) {
            if p2*p1 is in your range, add it to the answer
            //optimization: break when you know you won't find any more
        }
    }
    // optimization: calculate the ranges of p1 and p2 to be included 
    // before you start each loop
    // (probably only worthwhile if you raise the limit to something 
    // much larger than 1000)
    

    It’s certainly fast enough for numbers on this scale. I have it in under a millisecond (to find 292 numbers between 0 and 1000. I used hardcoded primes — you only need 95 of them for this range of inputs.)

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

Sidebar

Related Questions

I need to sort an array that can look like this: $array[4][0] = array('id'
the id filed is a Integer(from 1 to Integer.MAX_VALUE,unique), I don't need range searches
My need is to sort the ArrayList of Strings, based on specific index range.
I need to build a full number range set given a series of numbers.
I need to select a range of rows and sort that range by column
I need to sort a flat file by third column leaving first column intact
I need to sort list of strings in the alphabetical order: List<String> list =
I need to sort nodes in xml. I have the following code which successfully
I need to sort on a date-field type, which name is mod_date. It works
I need to sort close to a 1,00,000 floating point entries in Delphi. I

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.