- Trial division : try to divide by a number between and . It is always a worst case since any number can be picked.

- Fermat's factorization algorithm : note that if you set with and , then it becomes or . It becomes clear that the nearer a prime factor is from the square root of , the easier the algorithm becomes. However, if a prime factor is very small, then this algorithm is possibly the worst ever.

- Linear sieve : start from , and try divisions by increasing by each time. The worst case will be if . That must be your point.

There are lots of better methods, like the quadratic sieve or general number field sieve, but I'm not really good at explaining them so I will let Wikipedia do it

The worst case for factoring semiprimes in terms of arithmetic complexity really depends on the method used.

- Trial division : try to divide by a number between and . It is always a worst case since any number can be picked.

- Fermat's factorization algorithm : note that if you set with and , then it becomes or . It becomes clear that the nearer a prime factor is from the square root of , the easier the algorithm becomes. However, if a prime factor is very small, then this algorithm is possibly the worst ever.

- Linear sieve : start from , and try divisions by increasing by each time. The worst case will be if . That must be your point.

There are lots of better methods, like the quadratic sieve or general number field sieve, but I'm not really good at explaining them so I will let Wikipedia do it

The worst case for factoring semiprimes in terms of arithmetic complexity really depends on the method used.

I was sure I'd put it in there - sorry about that. The method being used is trial division.

So you're saying n=pg with pq close together is the worst case since if you pick numbers randomly to try, you're unlikely to get within that ball park which will give you the right answer?

No, in trial division, the worst case is any number, since you are equally likely to pick the right number.

It takes longer than because in , there are two prime factors only, and in , there are three, so you have a bit more chance of finding the right number.

-----------------------

In trial division, you are looking for , with . It is necessary that , thus.
Basically, you just pick random numbers between and , until you fall on a number that divides . At this moment, you know you found , and you can find easily.