SLUG Mailing List Archives
Re: [SLUG] c++... a bit OT
- To: slug@xxxxxxxxxxx
- Subject: Re: [SLUG] c++... a bit OT
- From: James Wilkinson <jamesw@xxxxxxxxxxxxxxxxxxx>
- Date: Wed Nov 15 11:36:56 2000
- Reply-to: Some Linux Users Group <slug@xxxxxxxxxxx>
- User-agent: Mutt/1.2.5i
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 ;)
> 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
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.
Another way, is to do your computations in binary, then you can mask off
the last couple of bits. i.e.: 1, 2, 3, 5, 7, 9, B, C, F are prime, you
can get the last 8 bits of an int by doing something like last8 = num &
Sure, I subscribe to USENET, but I only get it for the articles.