Let's say we have a number of divisors N. And I want to find a minimum number
that has N divisors.
My algorithm
pm[i]^(rp[i]-1)
, i = 1...length of prime factorsFor the N=12, answer is 60 = 2^(3-1) * 3^(2-1) * 5^(2-1)
But for the number 243 my algorithm gives wrong answer (5336100 - but it is not minimum number that has 243 divisors). Expected number is 2822400
.
Where is my fault? Any literature?
The Best Approach will be to traverse for every number and calculate the number of factors. Then check if the count is equal to or more than n then we get our desired smallest integer with n or more factors.
And that's the only way we can find numbers with exactly n divisors: We write n as a product n = n1 * n2 * n3 ..., then find primes p1, p2, p3 and so on, and the product p1n1−1p2n2−1p3n3−1... has exactly n divisors.
The number of divisors = The product of the exponents of prime factors + 1 for each prime factor. That is: 2^6 x 3^1 =[6 +1] x [1 + 1] =7 x 2 = 14 divisors. Therefore, 2^6 x 3^1 = 192 is the smallest number with EXACTLY 14 divisors.
Let's start with the OEIS sequence. Now any number can be expressed as product of prime powers.
How many divisors will it have? You can prove using combinatorics that it will have:
So you have to solve the equation where the expression above is equal to the number of divisions that you have. I will not write a code here, but notice that because you are looking for integer solutions, you can factor out your number of divisors.
When you will find your m_i
, you can get your smallest number by sorting m_i
and assigning biggest m_i
to smallest prime. So if your m1 = 2
, m2 = 5
, m3 = 2
, the number will be 2^5 * 3^2 * 5^2
.
Building upon SalvadorDali's answer:
Given that N is the product of (mi + 1), you have attempted to find mi by computing the prime factorization of N, and then subtracting 1 from each factor.
That doesn't necessarily give the minimum answer, as shown by your example with N=243. The prime factorization of 243 is
243 = 3*3*3*3*3
so your method suggests that the minimum should be
2^2 * 3^2 * 5^2 * 7^2 * 11^2 = 5336100
However, the alternative composite factorization of 243 is
243 = 9*3*3*3
which suggests that the minimum should be
2^8 * 3^2 * 5^2 * 7^2 = 2822400
The composite factorization works better because 2^6 is less than 11^2. So in general, your method is only a starting point. After computing your answer, you need to fold the largest primes into the smallest primes to improve the answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With