/* Find the first apparent prime in ascending order from z */ mp_result mp_int_find_prime(mp_int z) { mp_result res; if(mp_int_is_even(z) && ((res = mp_int_add_value(z, 1, z)) != MP_OK)) return res; while((res = mp_int_is_prime(z)) == MP_FALSE) { if((res = mp_int_add_value(z, 2, z)) != MP_OK) break; } return res; }
mp_result find_prime(mp_int seed, FILE *fb) { mp_result res; int count = 0; if(mp_int_is_even(seed)) if((res = mp_int_add_value(seed, 1, seed)) != MP_OK) return res; while((res = mp_int_is_prime(seed)) == MP_FALSE) { ++count; if(fb != NULL && (count % 50) == 0) fputc('.', fb); if((res = mp_int_add_value(seed, 2, seed)) != MP_OK) return res; } if(res == MP_TRUE && fb != NULL) fputc('+', fb); return res; }