Jump to content

Unprimeable numbers: Difference between revisions

→‎{{header|REXX}}: simplified parts of the program, optimized for speed.
(→‎{{header|Wren}}: Now uses Wren-math module.)
(→‎{{header|REXX}}: simplified parts of the program, optimized for speed.)
Line 1,775:
if !.new then iterate j /*This new number a prime? " " */
end /*e_*/
 
meat= right(j, L-1) /*obtain the last L-1 digits of J. */
/* [↑] examine a new 1st digit of J. */
do f_=0 for 10; new= (f_||meat) + 0 /*obtain a different number (than J).*/
Line 1,794 ⟶ 1,792:
if #<=n then $$= $$ commas(j) /*maybe add unprimeable # to $$ list.*/
if #==x then $.ox= commas(j) /*assign the Xth unprimeable number.*/
_= right(j, 1)parse var j '' -1 _ /*obtain the right─most dec digit of J.*/
if $._==. then $._= j /*the 1st unprimeable # that ends in _.*/
if $.3==. then iterate; if $.7==. then iterate /*test if specific #'s found.*/
Line 1,814 ⟶ 1,812:
th:procedure;parse arg x;return x||word('th st nd rd',1+(x//10)*(x//100%10\==1)*(x//10<4))
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6= 13; nP@.7=617; /*assign low@.8=19; primes@.9=23; # primes@.10=29; */ #p=10
!.=0; !.2=1; !.3=1; !.5=1; !.7=1; !.11=1; /*assign some!.13=1; !.17=1; low!.19=1; semaphore primes!.23=1; */!.29=1
do lim=100 until lim*lim>=hp; end /*only keep primes up to the sqrt(hp). */
do j=@.nP+4 by 2 to hp end /*lim*/ /*only find[↑] odd primesfind fromlimit here on.for storing primes. */
ifdo j// 3==0@.#p+2 thenby 2 to hp iterate /*isonly Jfind divisibleodd byprimes from #3here on. Then not prime*/
parse var j '' -1 _;if _==5 then iterate /*IsGet last digit; a "5"? is last digit a " 5" " ?*/
if j// 73==0 then iterate /*is J divisible by 73? Then not " " " prime*/
if j// 7==0 then iterate /* " " " " 7? " " " */
if j//11==0 then iterate /* " " " " 11? " " " */
if j//13==0 then iterate /*is " " " " 13? " " " */
if j//17==0 dothen k=7iterate while k /*k<=j " " " " 17? " /*divide by some" generated odd" primes. */
if j//19==0 then iterate /* " " " " 19? " " " */
if j//23==0 then iterate /* " " " " 23? " " " */
if j//29==0 then iterate /* " " " " 29? " " " */
do k=11 while k*k<=j /*divide by some generated odd primes. */
if j // @.k==0 then iterate j /*Is J divisible by P? Then not prime*/
end /*k*/ /* [↓] a prime (J) has been found. */
nP#p= nP#p+1; if nP#p<=lim then @.nP#p=j; !.j=1 /*bump prime count; assign prime to @.*/
end /*j*/; return</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.