I'm not much of a coder but from a mathematical point of view, it would be quicker to use the square root function instead of the primehalf that you use. Also you can check for divisibility by 2 in a seperate step, then set your divisor=3 at the start and increase by 2 instead (since you only need to check the odd numbers).