Primality by trial division: Difference between revisions
Content deleted Content added
mNo edit summary |
mNo edit summary |
||
Line 2,361:
w = 6 - w
end return 1
</lang>
=={{header|Ring}}==
<lang ring>give n
flag = 0
flag = isPrime(n)
if flag = 1 see n + nl see " is a prime number"
else see n + nl see " is not a prime number" ok
func isPrime n
flag = 1
if n <= 1 return 0 ok
if n = 2 or n = 3 return 1 ok
if n % 2 = 0 return 0 ok
if n % 3 = 0 return 0 ok
i = 5
w = 2
while i * i <= n
if n % i = 0 return 0 ok
i = i + w
w = 6 - w
end return 1
</lang>
|