From 874cc75431fb8ade1ca7c154bc8ddff47e89f502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20A=2E=20Ortega=20Froysa?= Date: Thu, 18 Oct 2018 23:04:12 +0200 Subject: [PATCH] Only test up to the sqrt. --- src/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 29e954d..089609d 100644 --- a/src/main.c +++ b/src/main.c @@ -56,7 +56,11 @@ int main(int argc, char *argv[]) { { struct llist_item *item = prime_list.first; int is_prime = 1; - while(item) + + mpz_t root; + mpz_init(root); + mpz_sqrt(root, aux); + while(item && mpz_cmp(item->num, root) < 0) { if(mpz_divisible_p(aux, item->num)) { @@ -79,6 +83,7 @@ int main(int argc, char *argv[]) { printf("The %zu prime is ", prime_list.size); mpz_out_str(stdout, 10, prime_list.last->num); + printf("\n"); llist_deinit(&prime_list); return 0;