2 * UCW Library -- Prime Number Tests
4 * (c) 1997 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include <ucw/prime.h>
13 static int /* Sequential search */
14 __isprime(uns x) /* We know x != 2 && x != 3 */
39 return (x == 2 || x == 3);
51 nextprime(uns x) /* Returns some prime greater than x */
53 x += 5 - (x % 6); /* x is 6k-1 */
71 main(int argc, char **argv)
73 uns k = atol(argv[1]);
74 printf("%d is%s prime\n", k, isprime(k) ? "" : "n't");
75 printf("Next prime is %d\n", nextprime(k));