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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:35:58+00:00 2026-06-11T08:35:58+00:00

Is there a know algorithm to factor an integer into as few factors as

  • 0

Is there a know algorithm to factor an integer into as few factors as possible (not necessarily prime) where every factor is less than some given constant N?

I don’t care about numbers with a prime factor greater than N. Also, I’m not dealing with numbers greater than a few million and the factoring is part of the processing initialization, so I’m not especially worried about computational complexity.

EDIT: Just to be clear. I already have code find the prime factors. I’m looking for a way to combine those factors into as few composite factors as possible while keeping each factor less than N.

  • 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-11T08:36:00+00:00Added an answer on June 11, 2026 at 8:36 am

    You can solve your problem by dividing it into two parts:

    1. Factorize your number into primes using any of the standard techniques. For a number of only a few million, trial division would be perfectly fine.

    2. Take the logarithm of each factor, and pack them into bins of size log N.

    Now, bin packing is NP-hard but in practice it is possible to find good approximate solutions using simple techniques: the first-fit algorithm packs no more than 11/9 times the optimal number of bins (plus one bin).

    Here’s an implementation in Python:

    from math import exp, log, sqrt
    import operator
    
    def factorize(n):
        """
        Factorize n by trial division and yield the prime factors.
    
        >>> list(factorize(24))
        [2, 2, 2, 3]
        >>> list(factorize(91))
        [7, 13]
        >>> list(factorize(999983))
        [999983]
        """
        for p in xrange(2, int(sqrt(n)) + 1):
            while n % p == 0:
                yield p
                n //= p
            if n == 1:
                return
        yield n
    
    def product(s):
        """
        Return the product of the items in the sequence `s`.
    
        >>> from math import factorial
        >>> product(xrange(1,10)) == factorial(9)
        True
        """
        return reduce(operator.mul, s, 1)
    
    def pack(objects, bin_size, cost=sum):
        """
        Pack the numbers in `objects` into a small number of bins of size
        `bin_size` using the first-fit decreasing algorithm. The optional
        argument `cost` is a function that computes the cost of a bin.
    
        >>> pack([2, 5, 4, 7, 1, 3, 8], 10)
        [[8, 2], [7, 3], [5, 4, 1]]
        >>> len(pack([6,6,5,5,5,4,4,4,4,2,2,2,2,3,3,7,7,5,5,8,8,4,4,5], 10))
        11
        """
        bins = []
        for o in sorted(objects, reverse=True):
            if o > bin_size:
                raise ValueError("Object {0} is bigger than bin {1}"
                                 .format(o, bin_size))
            for b in bins:
                new_cost = cost([b[0], o])
                if new_cost <= bin_size:
                    b[0] = new_cost
                    b[1].append(o)
                    break
            else:
                b = [o]
                bins.append([cost(b), b])
        return [b[1] for b in bins]
    
    def small_factorization(n, m):
        """
        Factorize `n` into a small number of factors, subject to the
        constraint that each factor is less than or equal to `m`.
    
        >>> small_factorization(2400, 40)
        [25, 24, 4]
        >>> small_factorization(2400, 50)
        [50, 48]
        """
        return [product(b) for b in pack(factorize(n), m, cost=product)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not a request for a queueing algorithm, I know there are plenty.
I would like to know if there's an efficient algorithm to find the greatest
I know there are a few workarounds to create an always visible bottom menu
I know there is an algorithm for seeing how close two words are together.
I know there's a not on ienumerable thanks to linq which takes a collection
I have an algorithm that works perfectly, but it uses recursion. I know there
I know there are several ways of creating a free trials. My algorithm that
I know there are several techniques out there to encrypt data. I am not
I am trying to implement a K-means algorithm in Python (I know there is
I would like to know if there exist algorithms that solves this issue. It

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.