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

The Archive Base Latest Questions

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

I’m looking for an efficient algorithm for computing the multiplicative partitions for any given

  • 0

I’m looking for an efficient algorithm for computing the multiplicative partitions for any given integer. For example, the number of such partitions for 12 is 4, which are

12 = 12 x 1 = 4 x 3 = 2 x 2 x 3 = 2 x 6

I’ve read the wikipedia article for this, but that doesn’t really give me an algorithm for generating the partitions (it only talks about the number of such partitions, and to be honest, even that is not very clear to me!).

The problem I’m looking at requires me to compute multiplicative partitions for very large numbers (> 1 billion), so I was trying to come up with a dynamic programming approach for it (so that finding all possible partitions for a smaller number can be re-used when that smaller number is itself a factor of a bigger number), but so far, I don’t know where to begin!

Any ideas/hints would be appreciated – this is not a homework problem, merely something I’m trying to solve because it seems so interesting!

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

    Of course, the first thing to do is find the prime factorisation of the number, like glowcoder said. Say

    n = p^a * q^b * r^c * ...
    

    Then

    1. find the multiplicative partitions of m = n / p^a
    2. for 0 <= k <= a, find the multiplicative partitions of p^k, which is equivalent to finding the additive partitions of k
    3. for each multiplicative partition of m, find all distinct ways to distribute a-k factors p among the factors
    4. combine results of 2. and 3.

    It is convenient to treat the multiplicative partitions as lists (or sets) of (divisor, multiplicity) pairs to avoid producing duplicates.

    I’ve written the code in Haskell because it’s the most convenient and concise of the languages I know for this sort of thing:

    module MultiPart (multiplicativePartitions) where
    
    import Data.List (sort)
    import Math.NumberTheory.Primes (factorise)
    import Control.Arrow (first)
    
    multiplicativePartitions :: Integer -> [[Integer]]
    multiplicativePartitions n
        | n < 1     = []
        | n == 1    = [[]]
        | otherwise = map ((>>= uncurry (flip replicate)) . sort) . pfPartitions $ factorise n
    
    additivePartitions :: Int -> [[(Int,Int)]]
    additivePartitions 0 = [[]]
    additivePartitions n
        | n < 0     = []
        | otherwise = aParts n n
          where
            aParts :: Int -> Int -> [[(Int,Int)]]
            aParts 0 _ = [[]]
            aParts 1 m = [[(1,m)]]
            aParts k m = withK ++ aParts (k-1) m
              where
                withK = do
                    let q = m `quot` k
                    j <- [q,q-1 .. 1]
                    [(k,j):prt | let r = m - j*k, prt <- aParts (min (k-1) r) r]
    
    countedPartitions :: Int -> Int -> [[(Int,Int)]]
    countedPartitions 0     count = [[(0,count)]]
    countedPartitions quant count = cbParts quant quant count
      where
        prep _ 0 = id
        prep m j = ((m,j):)
        cbParts :: Int -> Int -> Int -> [[(Int,Int)]]
        cbParts q 0 c
            | q == 0    = if c == 0 then [[]] else [[(0,c)]]
            | otherwise = error "Oops"
        cbParts q 1 c
            | c < q     = []        -- should never happen
            | c == q    = [[(1,c)]]
            | otherwise = [[(1,q),(0,c-q)]]
        cbParts q m c = do
            let lo = max 0 $ q - c*(m-1)
                hi = q `quot` m
            j <- [lo .. hi]
            let r = q - j*m
                m' = min (m-1) r
            map (prep m j) $ cbParts r m' (c-j)
    
    primePowerPartitions :: Integer -> Int -> [[(Integer,Int)]]
    primePowerPartitions p e = map (map (first (p^))) $ additivePartitions e
    
    distOne :: Integer -> Int -> Integer -> Int -> [[(Integer,Int)]]
    distOne _ 0 d k = [[(d,k)]]
    distOne p e d k = do
        cap <- countedPartitions e k
        return $ [(p^i*d,m) | (i,m) <- cap]
    
    distribute :: Integer -> Int -> [(Integer,Int)] -> [[(Integer,Int)]]
    distribute _ 0 xs = [xs]
    distribute p e [(d,k)] = distOne p e d k
    distribute p e ((d,k):dks) = do
        j <- [0 .. e]
        dps <- distOne p j d k
        ys <- distribute p (e-j) dks
        return $ dps ++ ys
    distribute _ _ [] = []
    
    pfPartitions :: [(Integer,Int)] -> [[(Integer,Int)]]
    pfPartitions [] = [[]]
    pfPartitions [(p,e)] = primePowerPartitions p e
    pfPartitions ((p,e):pps) = do
        cop <- pfPartitions pps
        k <- [0 .. e]
        ppp <- primePowerPartitions p k
        mix <- distribute p (e-k) cop
        return (ppp ++ mix)
    

    It’s not particularly optimised, but it does the job.

    Some times and results:

    Prelude MultiPart> length $ multiplicativePartitions $ 10^10
    59521
    (0.03 secs, 53535264 bytes)
    Prelude MultiPart> length $ multiplicativePartitions $ 10^11
    151958
    (0.11 secs, 125850200 bytes)
    Prelude MultiPart> length $ multiplicativePartitions $ 10^12
    379693
    (0.26 secs, 296844616 bytes)
    Prelude MultiPart> length $ multiplicativePartitions $ product [2 .. 10]
    70520
    (0.07 secs, 72786128 bytes)
    Prelude MultiPart> length $ multiplicativePartitions $ product [2 .. 11]
    425240
    (0.36 secs, 460094808 bytes)
    Prelude MultiPart> length $ multiplicativePartitions $ product [2 .. 12]
    2787810
    (2.06 secs, 2572962320 bytes)
    

    The 10^k are of course particularly easy because there are only two primes involved (but squarefree numbers are still easier), the factorials get slow earlier. I think by careful organisation of the order and choice of better data structures than lists, there’s quite a bit to be gained (probably one should sort the prime factors by exponent, but I don’t know whether one should start with the highest exponents or the lowest).

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.