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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:35:16+00:00 2026-05-31T16:35:16+00:00

I need to find all monomials in the form A X that when evaluated

  • 0

I need to find all monomials in the form AX that when evaluated falls within a range from m to n. It is safe to say that the base A is greater than 1, the power X is greater than 2, and only integers need to be used. For example, in the range 50 to 100, the solutions would be:

2^6
3^4
4^3

My first attempt to solve this was to brute force all combinations of A and X that make “sense.” However this becomes too slow when used for very large numbers in a big range since these solutions are used in part of much more intensive processing. Here is the code:

def monoSearch(min, max):
    base = 2
    power = 3

    while 1:
        while base**power < max:
            if base**power > min:
                print "Found " + repr(base) + "^" + repr(power) + "   = " + repr(base**power)    
            power = power + 1
        base = base + 1
        power = 3
        if base**power > max:
            break

I could remove one base**power by saving the value in a temporary variable but I don’t think that would make a drastic effect. I also wondered if using logarithms would be better or if there was a closed form expression for this. I am open to any optimizations or alternatives to finding the solutions.

  • 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-31T16:35:17+00:00Added an answer on May 31, 2026 at 4:35 pm

    Don’t search; consider the endpoints.

    For example, all the solutions with x == 3 are such that a is between the cube root of m and the cube root of n. So calculate those cube roots and use the range of integers in between. Since a is at least 2, the maximum x is log base 2 of n, so that’s how you know when to stop.

    from math import log, ceil, floor
    
    def monoSearch(low, high):
        max_power = int(floor(log(high) / log(2)))
        for power in range(3, max_power + 1):
            min_base = low ** (1.0 / power)
            max_base = high ** (1.0 / power)
            for base in range(int(ceil(min_base)), int(floor(max_base)) + 1):
                yield '%s ^ %s' % (base, power)
    
    print '\n'.join(monoSearch(42, 1000000))
    

    This may miss a couple of values due to floating-point imprecision, unfortunately.

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

Sidebar

Related Questions

Let's say i need to find all .bar elements inside an element that's assigned
I need to find all substrings from a string that starting with a given
I need to find all the zipcodes with a certain range from a zipcode.
I need to find all instances of strings within an xml node. To be
I need to find all image files from directory (gif, png, jpg, jpeg). find
I need to find all patrons that have at least 1 circulation record. Here's
I need to be able to find all grids for a given form. This
I need to find all the records that have no associated records in any
I have a web application where I need to find all classes that accesses
I need to find all the classes derived from System.Web.UI.Page which reference another class

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.