X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fprime.c;h=9be4c411c05ece16c9c1c550d89812498c4e371c;hb=cab386086509de5dd4b87179d9e149c017fdc707;hp=0ed0eda107c308e3e8123156037d97c41bf7cc73;hpb=49ed04e2e93a6a5b01058638224621d5c07db01c;p=libucw.git diff --git a/lib/prime.c b/lib/prime.c index 0ed0eda1..9be4c411 100644 --- a/lib/prime.c +++ b/lib/prime.c @@ -47,32 +47,32 @@ isprime(uns x) } uns -nextprime(uns x) /* Returns some prime greater than X, usually the next one or the second next one */ +nextprime(uns x) /* Returns some prime greater than x */ { x += 5 - (x % 6); /* x is 6k-1 */ for(;;) { - if (__isprime(x)) - return x; x += 2; /* 6k+1 */ if (__isprime(x)) return x; x += 4; /* 6k-1 */ + if (__isprime(x)) + return x; } } #ifdef TEST #include +#include int main(int argc, char **argv) { uns k = atol(argv[1]); - if (isprime(k)) - printf("%d is prime\n"); - else - printf("Next prime is %d\n", nextprime(k)); + printf("%d is%s prime\n", k, isprime(k) ? "" : "n't"); + printf("Next prime is %d\n", nextprime(k)); + return 0; } #endif