Factors In Java

Beanie Leung :

I am trying to compute a list of prime factors of the ​factorial of n, with the prime factors sorted in increasing order and with each in this list exactly as many times as it would appear in the prime factorization of the factorial.

I have a program that computes a linkedlist of prime numbers up to a specified number, but I'm not sure how to implement that while appending the prime factors of the integer that is currently being multiplied into the factorial:

Dushyant Singh :
public static List<Integer> getFactorialPrimeFactors(int n)
{
    List <Integer> primes = primeNum(n);

    ArrayList <Integer> primeDivisors = new ArrayList<>();
    for(int i: primes)
    {
        int count = 0;
        for(int num = i; num <= n; num *= i)
        {
            count += n/num;
        }

        while(count > 0)
        {
            primeDivisors.add(i);
            count--;
        }
    }

    return primeDivisors;
}

Explanation - https://math.stackexchange.com/a/642220

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=350556&siteId=1