Re: prime number
From: SM Ryan (wyrmwif_at_tango-sierra-oscar-foxtrot-tango-dot-charlie-oscar-mike.fake.org)
Date: 05/21/04
- Next message: Jesuis: "Touchadvertising."
- Previous message: Chika: "prime number"
- In reply to: Chika: "prime number"
- Next in thread: Randy Howard: "Re: prime number"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 21 May 2004 05:34:19 -0000
e265koba@st.yatsushiro-nct.ac.jp (Chika) wrote:
# I want to create the program which asks for whether a certain number
# is a prime number using bc (calculation language).
# However, I do not understand the method of a judgment of
# a prime number.
# Please let me know someone.
In general, divide N by each prime less than it, and see if the remainder
is zero. If so for any lesser prime, it is a composite.
(1) You probably don't have a list of all prime numbers handy. Instead you
can divide by N by all numbers from 2 and N-1. That will include all primes
less than N.
(2) You can get a linear speed up by special case division by 2 and then
only dividing by subsequent odd numbers. Et cetera.
(3) If p*p>N, if pq = N, q<p. Thus you only have to test divide up sqrt(N),
not all the way to N-1.
Factorring/testing for prime has no known fast solution. Some codes depend
on this situation.
-- SM Ryan http://www.rawbw.com/~wyrmwif/ But I do believe in this.
- Next message: Jesuis: "Touchadvertising."
- Previous message: Chika: "prime number"
- In reply to: Chika: "prime number"
- Next in thread: Randy Howard: "Re: prime number"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|