I'm trying to understand what the issue is with creating an efficient prime factorisation algorithm. Specifically, the research I've done so far says that no algorithm has yet been discovered which can find the prime factors of a number in O(n2) time. However, the obvious algorithm to me is something like (pseudocode)
method(int number, ArrayList<int> listOfPrimes)
{
int x = 0;
for (int i : listOfPrimes)
{
for (int j : listOfPrimes)
{
if (i * j = number)
{
x = i*j;
}
}
}
return x;
}
I think method is O(n2), where n is the size of the list. Clearly my understanding of this issue is flawed or there wouldn't be such a fuss about prime factorisation. Where am I going wrong?
A more optimal way would be
this returns the count prime factors of a number. the complexity would be
where n is the length of listOfPrimes