Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 alpha 4/3/85; site ukma.UUCP Path: utzoo!watmath!clyde!cbosgd!ukma!sambo From: sambo@ukma.UUCP (Inventor of micro-S) Newsgroups: net.micro Subject: Re: Z-100 vs IBM-AT Challenge Update Message-ID: <1805@ukma.UUCP> Date: Thu, 23-May-85 19:51:45 EDT Article-I.D.: ukma.1805 Posted: Thu May 23 19:51:45 1985 Date-Received: Sat, 25-May-85 00:25:20 EDT Organization: U of Kentucky, Mathematical Sciences, Lexington KY Lines: 41 Summary: A couple simple modifications to the prime number generator posted earlier produces a 10% speed increase on the VAX 11/750 Expires: References: <10787@brl-tgr.ARPA> Sender: Reply-To: sambo@ukma.UUCP (Inventor of micro-S) Followup-To: Distribution: Organization: Univ. of KY Mathematical Sciences Keywords: /* * Yet Another Prime number generator */ #define MAXPRIME 3300 #define MAXN 32767 int index, dividend, product, inc = 4, /* increment to add to n - oscillates between 2 and 4 */ n = 5, nprime = 1, prime[MAXPRIME] = {2, 3}; main() { /* note that n is never divisible by 3 because of how it is incremented */ for ( ; (nprime < MAXPRIME-1) && (n <= MAXN); n += (inc = 4 - inc + 2)) { /* start with index = 2 instead of 1 to avoid dividing by three */ for (index = 2, dividend = n ; (index < nprime) && (dividend > prime[index]); index++) if ((product = (dividend = n / prime[index]) * prime[index]) == n) break; if (product != n) prime[++nprime] = n; } printf("There are %d primes less than %d. The largest is %d.\n", nprime + 1, n, prime[nprime]); }