SLUG Mailing List ArchivesOn Wed, Nov 15, 2000 at 11:37:18AM +1100, James Wilkinson wrote: > This one time, at band camp, alex060@xxxxxxxxxxxxxxxx said: > > >all primes end in either 1 3 7 or 9 except 2 and 5 > > How about 39? That's not prime :) You need a better heuristic ;) No, he didn't say everything ending in 1 3 7 or 9 _is_ prime, just that to be prime you have to end in 1 3 7 or 9 (except 2 and 5) > > > so it is pointless to test it if it dosent ie ends in a 5, so how can i > >test to see if the last number is 1 3 7 9 before i start the curnum % x > >!=0 > > Well, you could convert it to a string, and look at the last character. > I think you're going to spend more time in the conversion than you think > you'd save by using it. number % 10 will give you the last digit. There are much better methods of finding prime numbers, though. sci.crypt has a lot of info about them. Stephen -- Stephen Norris srn@xxxxxxxxx Farrow Norris Pty Ltd +61 2 417 243 239
Attachment:
pgpoTrBaCXgiW.pgp
Description: PGP signature