Re: prime number routine
puppet_sock_at_hotmail.com
Date: 02/10/04
- Next message: Ed Falis: "Re: No call for Ada (was Re: Announcing new scripting/prototyping language)"
- Previous message: puppet_sock_at_hotmail.com: "Re: placement new , is this acceptable?"
- In reply to: don: "prime number routine"
- Next in thread: Ben Dover: "Re: prime number routine"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 10 Feb 2004 10:33:39 -0800
"don" <don@panix.com> wrote in message news:<c09uos$hjo$1@reader2.panix.com>...
> Ok, this is a homework assignment, but can you help me out anyway...... I
> need a routine for figuring out if a number inputted by the user is a prime
> number or not...... all I'm asking for is Not the exact code ( well maybe a
> little) but the logic or algorithm to tell whether or not a number is
> prime....
Precompute a big table of primes up to some maximum size.
Get your number. If it is smaller than the max, then
if it is in the table it is prime and if not not. Miller time.
If it is bigger than your max, then you have to start doing
some dividing. But first, you don't need to divide by anything
bigger than the square root of the number. (You have to explain
why.) And you don't need to divide by any number that is itself
not prime. (Again, you have to explain why.)
So, if your number is smaller than the square of the max of your
table, again, the scheme is pretty easy. You only need to divide
by the numbers in your table.
If your number is bigger than that, then you are on your own.
Socks
- Next message: Ed Falis: "Re: No call for Ada (was Re: Announcing new scripting/prototyping language)"
- Previous message: puppet_sock_at_hotmail.com: "Re: placement new , is this acceptable?"
- In reply to: don: "prime number routine"
- Next in thread: Ben Dover: "Re: prime number routine"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|