home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!mickey!bsmith
- From: bsmith@mickey.NoSubdomain.NoDomain (Brian Smith)
- Newsgroups: comp.programming
- Subject: Re: how about PRIME numbers ?
- Date: 25 Jan 1993 01:28:26 GMT
- Organization: University of California, Berkeley
- Lines: 22
- Sender: bsmith@mickey (Brian Smith)
- Distribution: world
- Message-ID: <1jvfnq$rvn@agate.berkeley.edu>
- References: <peterd.727578786@tscc2> <1993Jan24.055343.2392@organpipe.uug.arizona.edu>
- NNTP-Posting-Host: mickey.cs.berkeley.edu
-
- In article <1993Jan24.055343.2392@organpipe.uug.arizona.edu>,
- dave@cs.arizona.edu (Dave Schaumann) writes:
- |> int is_prime( unsigned long n ) {
- |>
- |> unsigned long i, max = sqrt(n) ;
- |>
- |> if( n <= 3 ) return 1 ;
- |>
- |> if( n % 2 == 0 || n % 3 == 0 ) return 0 ;
- |> for( i = 6 ; i <= max+1 ; i += 6 )
- |> if( n % (i-1) == 0 || n % (i+1) == 0 ) return 0 ;
- |>
- |> return 1 ;
-
- Slight bug. The for loop should go to max+2, not max+1
-
- Nice trick!
-
- -------
- Brian C. Smith arpa: bsmith@cs.Berkeley.EDU
- University of California, Berkeley uucp: uunet!ucbvax!postgres!bsmith
- Computer Sciences Department phone: (510)642-9585
-