Prime generator: fixed logic