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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:59:50+00:00 2026-06-09T07:59:50+00:00

I am working on Project Euler problem 5 and am using the following: def

  • 0

I am working on Project Euler problem 5 and am using the following:

def findLCM(k):
start=time.time()
primes=[2,3,5,7,11,13,17,19,23]
factors=[]
for factor in range(2,k):
    if factor in primes:
        factors.append(factor)
    else:
        factorization=[]
        while factor!=1:
            for prime in primes:
                lastFactor=prime
                if factor%prime==0:
                    factor/=prime
                    factorization.append(lastFactor)
                    break
        tmpFactors=[]
        for tmpFactor in factorization:
            if tmpFactor not in factors:
                factors.append(tmpFactor)
            else:
                tmpFactors.append(tmpFactor)
                factors.remove(tmpFactor)
        for tmpFactor in tmpFactors:
            factors.append(tmpFactor)
        print factors
product=1
for factor in factors:
    product*=factor
factors.sort()
end=time.time()
fnTime=end-start
return product, fnTime, factors

Is there a Python function with which I can combine factorization and factors like this function does? For example, if factors=[2, 3, 5] and factorization=[2, 2, 3], the combined list should be [2, 2, 3, 5].

  • 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-09T07:59:51+00:00Added an answer on June 9, 2026 at 7:59 am

    The terminology is “union of multisets“.

    It is implemented in Python using collections.Counter:

    >>> from collections import Counter
    >>> combined = Counter([2, 3, 5]) | Counter([2, 2, 3])
    >>> list(combined.elements())
    [2, 2, 3, 5]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm again working on Project Euler, this time problem #4. The point of this
I'm currently working on project euler problem 14 . I solved it using a
I'm working on problem four of Project Euler and am running into a stackoverflow
I'm working on problem 9 in Project Euler: There exists exactly one Pythagorean triplet
I'm currently working on a project Euler problem (www.projecteuler.net) for fun but have hit
Possible Duplicate: Project Euler, Problem 10 java solution not working So, I'm attempting to
I am working on Problem 14 on Project Euler, and my code seems to
I'll try to be concise this time around! I'm still working Project Euler, this
I'm working on problem 14 of Project Euler ( http://projecteuler.net/problem=14 ). I'm trying to
I am working on Project Euler Problem 4 , and need to find the

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.