Primality by trial division: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added syntax colouring the hard way, made runnable and added output) |
Not a robot (talk | contribs) (Add BCPL) |
||
Line 758: | Line 758: | ||
return(1) |
return(1) |
||
}</lang> |
}</lang> |
||
=={{header|BCPL}}== |
|||
<lang bcpl>get "libhdr" |
|||
let sqrt(s) = |
|||
s <= 1 -> 1, |
|||
valof |
|||
$( let x0 = s >> 1 |
|||
let x1 = (x0 + s/x0) >> 1 |
|||
while x1 < x0 |
|||
$( x0 := x1 |
|||
x1 := (x0 + s/x0) >> 1 |
|||
$) |
|||
resultis x0 |
|||
$) |
|||
let isprime(n) = |
|||
n < 2 -> false, |
|||
(n & 1) = 0 -> n = 2, |
|||
valof |
|||
$( for i=3 to sqrt(n) |
|||
if n rem i = 0 resultis false |
|||
resultis true |
|||
$) |
|||
let start() be |
|||
$( for i=1 to 100 |
|||
if isprime(i) then writef("%N ",i) |
|||
wrch('*N') |
|||
$)</lang> |
|||
{{out}} |
|||
<pre>2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97</pre> |
|||
=={{header|Befunge}}== |
=={{header|Befunge}}== |