Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Lucas primality test
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Algorithm== The algorithm can be written in [[pseudocode]] as follows: '''algorithm''' lucas_primality_test '''is''' '''input''': ''n'' > 2, an odd integer to be tested for primality. ''k'', a parameter that determines the accuracy of the test. '''output''': ''prime'' if ''n'' is prime, otherwise ''composite'' or ''possibly composite''. determine the prime factors of ''n''−1. LOOP1: '''repeat''' ''k'' times: pick ''a'' randomly in the range [2, ''n'' β 1] {{nowrap|'''if''' <math>a^{n-1} \not\equiv 1 \pmod n</math> '''then'''}} '''return''' ''composite'' '''else''' {{nowrap|{{color|gray|#}} <math>\color{Gray}{a^{n-1} \equiv 1 \pmod n}</math>}} LOOP2: '''for''' all prime factors ''q'' of ''n''−1: {{nowrap|'''if''' <math>a^\frac{n-1}q \not\equiv 1 \pmod n</math> '''then'''}} '''if''' we checked this equality for all prime factors of ''n''−1 '''then''' '''return''' ''prime'' '''else''' '''continue''' LOOP2 '''else''' {{nowrap|{{color|gray|#}} <math>\color{Gray}{a^\frac{n-1}q \equiv 1 \pmod n}</math>}} '''continue''' LOOP1 '''return''' ''possibly composite''.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)