used trial division in the end.