Problem 3 solved but with a large CPU demand and solve time. Need to cut down on prime test function.