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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:32:16+00:00 2026-06-08T14:32:16+00:00

I’m trying to find the smallest number evenly divisible by each integer 1-20(inclusive). This

  • 0

I’m trying to find the smallest number evenly divisible by each integer 1-20(inclusive). This is just me trying to improve on a practice exercise I had done before.

I wrote a function that takes in an argument and returns the smallest number that is evenly divisible by every positive integer smaller than the argument including itself but, it is not optimized and runs relatively slow as the numbers get larger.

I was wanting to know what would the Big-O notation be for this function and why. Then, if any, are there ways to speed this up, maybe with memoization I am not sure?

def divide_by_all(x):
    ## the 'pos' variable will be matched up against the argument to keep track of how many of the numbers in ##
    ## the arguments range are dividing evenly. ##
    pos = 0
    ## the 'count' variable will be set to equal the input argument, possibly
    count = x
    ## create the range of integers for the argument ##
    divs = [i for i in range(1,x + 1)]
    while pos != x:
        for i in divs:
            ## check if each 'i' in the divs list is evenly divisible ##
            ## if 'i' is not evenly divisible the 'count'(answer) is incremented, the 'pos' is set back to zero to show ##
            ## the next 'count' has no evenly divisible in numbers div yet, and then loop over the divs list starts again ##
            if count % i != 0:
                count += 1
                pos = 0
                break
            ## if 'i' is evenly divides into current 'count' increment 'pos' ##
            if count % i == 0:
                pos += 1
            ## if 'pos' == the argument 'x', meaning every number in range(x) is evenly divisible ##
            ## return 'count' ##
            if pos == x:
                return count

Any tips and advice welcome!

  • 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-08T14:32:17+00:00Added an answer on June 8, 2026 at 2:32 pm

    It’s actually not that easy to give a good estimate of the asymptotic running time of this algorithm. As a ballpark estimate, it’s probably somewhat less than n! (i.e. VERY slow). The problem is simply that the answer grows quickly with n : it’s the product of the highest powers of the prime numbers less than n (for n=20, that would be 2^4 * 3^2 *5*7*11*13*17*19=232792560). As you check all numbers up to the answer, your running time is clearly greater than that (determining how much greater would take some work).

    Memoization is not pertinent here as your alogorithm is not recursive.

    Basically, this is a math problem, not an algorithmic one.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.