Anonymous user
Sequence of primes by trial division: Difference between revisions
Sequence of primes by trial division (view source)
Revision as of 21:26, 13 September 2014
, 9 years ago→{{header|REXX}}: changed comments and some program logic, made prime list (internal) complete with even prime, added output.
(→{{header|REXX}}: added the REXX language. -- ~~~~) |
(→{{header|REXX}}: changed comments and some program logic, made prime list (internal) complete with even prime, added output.) |
||
Line 63:
This is an open-ended approach and it's a simple implementation and could be optimized greatly.
<br>The method used is to divided all odd numbers by all previous odd primes up to and including the <big>'''√'''</big> of the odd number.
<lang rexx>/*REXX
parse arg n . /*let user choose how many, maybe*/
if n=='' then n=26 /*if not, then assume the default*/
if n<1 then exit /*handle special case of 0 primes*/
@.1=2; say right(
#=1 /*# is the number of primes found*/
/* [↑] N default lists up to 101*/
/* [↓] display the prime count. */
say # ' primes found.' /*stick a fork in it, we're done.*/</lang
'''output''' using the default input of: <tt> 26 </tt>
<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
101
26 primes found.
</pre>
=={{header|Scala}}==
|