Nice primes: Difference between revisions

m
add ooRexx
(Added XPL0 example.)
m (add ooRexx)
Line 1,158:
{{out}}
<pre>{509, 547, 563, 569, 587, 599, 601, 617, 619, 641, 653, 659, 673, 677, 691, 709, 727, 743, 761, 797, 821, 839, 853, 857, 887, 907, 911, 929, 941, 947, 977, 983, 997}</pre>
 
=={{header|ooRexx}}==
<lang oorexx>/* REXX */
n=1000
prime = .Array~new(n)~fill(.true)~~remove(1)
p.=0
Do i = 2 to n
If prime[i] = .true Then Do
Do j = i * i to n by i
prime~remove(j)
End
p.i=1
End
End
z=0
ol=''
Do i=500 To 1000
If p.i then Do
dr=digroot(i)
If p.dr Then Do
ol=ol' 'i'('dr')'
z=z+1
If z//10=0 Then Do
Say strip(ol)
ol=''
End
End
End
End
Say strip(ol)
Say z 'nice primes in the range 500 to 1000'
Exit
 
digroot:
Parse Arg s
Do Until length(s)=1
dr=0
Do j=1 To length(s)
dr=dr+substr(s,j,1)
End
s=dr
End
Return s</lang>
{{out}}
<pre>509(5) 547(7) 563(5) 569(2) 587(2) 599(5) 601(7) 617(5) 619(7) 641(2)
653(5) 659(2) 673(7) 677(2) 691(7) 709(7) 727(7) 743(5) 761(5) 797(5)
821(2) 839(2) 853(7) 857(2) 887(5) 907(7) 911(2) 929(2) 941(5) 947(2)
977(5) 983(2) 997(7)
33 nice primes in the range 500 to 1000</pre>
 
=={{header|PARI/GP}}==
2,295

edits