September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,33 +1,35 @@
|
|||
/*REXX program displays the N numbers of the first K k-almost primes*/
|
||||
parse arg N K . /*get the arguments from the C.L.*/
|
||||
if N=='' then N=10 /*No N? Then use the default.*/
|
||||
if K=='' then K=5 /* " K? " " " " */
|
||||
/* [↓] display one line per K.*/
|
||||
do m=1 for K; $=2**m; fir=$ /*generate the 1st k_almost prime*/
|
||||
#=1; if #==N then leave /*# k-almost primes; 'nuff found?*/
|
||||
sec=3*(2**(m-1)); $=$ sec; #=2 /*generate the 2nd k-almost prime*/
|
||||
do j=fir+fir+1 until #==N /*process an almost-prime N times*/
|
||||
if #factr(j)\==m then iterate /*not the correct k-almost prime?*/
|
||||
#=#+1 /*bump the k-almost prime counter*/
|
||||
$=$ j /*append k-almost prime to list. */
|
||||
end /*j*/ /* [↑] gen N k-almost primes.*/
|
||||
say N right(m,4)"-almost primes:" $ /*display the k-almost primes.*/
|
||||
end /*m*/ /* [↑] display a line for each K*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────#FACTR subroutine───────────────────*/
|
||||
#factr: procedure;parse arg x 1 z; f=0 /*defines X and Z to the arg.*/
|
||||
if x<2 then return 0 /*invalid number? Then return 0.*/
|
||||
do j=2 to 5; if j\==4 then call .#factr; end /*fast factoring.*/
|
||||
j=5 /*start were we left off (J=5). */
|
||||
do y=0 by 2; j=j+2 + y//4 /*insure it's not divisible by 3.*/
|
||||
if right(j,1)==5 then iterate /*fast check for divisible by 5.*/
|
||||
if j>z then leave /*number reduced to a wee number?*/
|
||||
call .#factr /*go add other factors to count. */
|
||||
end /*y*/ /* [↑] find all factors in X. */
|
||||
return max(f,1) /*if prime (f==0), then return 1.*/
|
||||
/*──────────────────────────────────.#FACTR subroutine──────────────────*/
|
||||
.#factr: do f=f+1 while z//j==0 /*keep dividing until we can't. */
|
||||
z=z%j /*perform an (%) integer divide.*/
|
||||
end /*while*/ /* [↑] whittle down the Z num.*/
|
||||
f=f-1 /*adjust the count of factors. */
|
||||
return
|
||||
/*REXX program computes and displays the first N K─almost primes from 1 ──► K. */
|
||||
parse arg N K . /*get optional arguments from the C.L. */
|
||||
if N=='' | N=="," then N=10 /*N not specified? Then use default.*/
|
||||
if K=='' | K=="," then K= 5 /*K " " " " " */
|
||||
/*W: is the width of K, used for output*/
|
||||
do m=1 for K; $=2**m; fir=$ /*generate & assign 1st K─almost prime.*/
|
||||
#=1; if #==N then leave /*#: K─almost primes; Enough are found?*/
|
||||
#=2; $=$ 3*(2**(m-1)) /*generate & append 2nd K─almost prime.*/
|
||||
if #==N then leave /*#: K─almost primes; Enough are found?*/
|
||||
if m==1 then _=fir + fir /* [↓] gen & append 3rd K─almost prime*/
|
||||
else do; _=9 * (2**(m-2)); #=3; $=$ _; end
|
||||
do j=_ + m - 1 until #==N /*process an K─almost prime N times.*/
|
||||
if factr()\==m then iterate /*not the correct K─almost prime? */
|
||||
#=# + 1; $=$ j /*bump K─almost counter; append it to $*/
|
||||
end /*j*/ /* [↑] generate N K─almost primes.*/
|
||||
say right(m, length(K))"─almost ("N') primes:' $
|
||||
end /*m*/ /* [↑] display a line for each K─prime*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
factr: z=j; do f=0 while z// 2==0; z=z% 2; end /*divisible by 2.*/
|
||||
do f=f while z// 3==0; z=z% 3; end /*divisible " 3.*/
|
||||
do f=f while z// 5==0; z=z% 5; end /*divisible " 5.*/
|
||||
do f=f while z// 7==0; z=z% 7; end /*divisible " 7.*/
|
||||
do f=f while z//11==0; z=z%11; end /*divisible " 11.*/
|
||||
do f=f while z//13==0; z=z%13; end /*divisible " 13.*/
|
||||
do p=17 by 6 while p<=z /*insure P isn't divisible by three. */
|
||||
parse var p '' -1 _ /*obtain the right─most decimal digit. */
|
||||
/* [↓] fast check for divisible by 5. */
|
||||
if _\==5 then do; do f=f+1 while z//p==0; z=z%p; end; f=f-1; end /*÷ by P? */
|
||||
if _ ==3 then iterate /*fast check for X divisible by five.*/
|
||||
x=p+2; do f=f+1 while z//x==0; z=z%x; end; f=f-1 /*÷ by X? */
|
||||
end /*i*/ /* [↑] find all the factors in Z. */
|
||||
|
||||
if f==0 then return 1 /*if prime (f==0), then return unity.*/
|
||||
return f /*return to invoker the number of divs.*/
|
||||
|
|
|
|||
|
|
@ -1,35 +1,66 @@
|
|||
/*REXX program displays the N numbers of the first K k-almost primes*/
|
||||
parse arg N K . /*get the arguments from the C.L.*/
|
||||
if N=='' then N=10 /*No N? Then use the default.*/
|
||||
if K=='' then K=5 /* " K? " " " " */
|
||||
/* [↓] display one line per K.*/
|
||||
do m=1 for K; $=2**m; fir=$ /*generate the 1st k_almost prime*/
|
||||
#=1; if #==N then leave /*# k-almost primes; 'nuff found?*/
|
||||
sec=3*(2**(m-1)); $=$ sec; #=2 /*generate the 2nd k-almost prime*/
|
||||
do j=fir+fir+1 until #==N /*process an almost-prime N times*/
|
||||
if #factL(j,m)\==m then iterate /*not the correct k-almost prime?*/
|
||||
#=#+1 /*bump the k-almost prime counter*/
|
||||
$=$ j /*append k-almost prime to list. */
|
||||
end /*j*/ /* [↑] gen N k-almost primes.*/
|
||||
say N right(m,4)"-almost primes:" $ /*display the k-almost primes.*/
|
||||
end /*m*/ /* [↑] display a line for each K*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────#FACTL subroutine───────────────────*/
|
||||
#factL: procedure; parse arg x 1 z,L /*defines X and Z to the arg.*/
|
||||
f=0; if x<2 then return 0 /*invalid number? Then return 0.*/
|
||||
do j=2 to 5; if j\==4 then call .#factL; end /*fast factoring.*/
|
||||
if f>L then return f /*#factors > L ? Then too many.*/
|
||||
j=5 /*start were we left off (J=5). */
|
||||
do y=0 by 2; j=j+2 + y//4 /*insure it's not divisible by 3.*/
|
||||
if right(j,1)==5 then iterate /*fast check for divisible by 5.*/
|
||||
if j>z then leave /*number reduced to a wee number?*/
|
||||
call .#factL /*go add other factors to count. */
|
||||
if f>L then return f /*#factors > L ? Then too many.*/
|
||||
end /*y*/ /* [↑] find all factors in X. */
|
||||
return max(f,1) /*if prime (f==0), then return 1.*/
|
||||
/*──────────────────────────────────.#FACTL subroutine──────────────────*/
|
||||
.#factL: do f=f+1 while z//j==0 /*keep dividing until we can't. */
|
||||
z=z%j /*perform an (%) integer divide.*/
|
||||
end /*while*/ /* [↑] whittle down the Z num.*/
|
||||
f=f-1 /*adjust the count of factors. */
|
||||
return
|
||||
/*REXX program computes and displays the first N K─almost primes from 1 ──► K. */
|
||||
parse arg N K . /*obtain optional arguments from the CL*/
|
||||
if N=='' | N==',' then N=10 /*N not specified? Then use default.*/
|
||||
if K=='' | K==',' then K= 5 /*K " " " " " */
|
||||
nn=N; N=abs(N); w=length(K) /*N positive? Then show K─almost primes*/
|
||||
limit= (2**K) * N / 2 /*this is the limit for most K-primes. */
|
||||
if N==1 then limit=limit * 2 /* " " " " " a N of 1.*/
|
||||
if K==1 then limit=limit * 4 /* " " " " " a K─prime " 2.*/
|
||||
if K==2 then limit=limit * 2 /* " " " " " " " " 4.*/
|
||||
if K==3 then limit=limit * 3 % 2 /* " " " " " " " " 8.*/
|
||||
call genPrimes limit + 1 /*generate primes up to the LIMIT + 1.*/
|
||||
say 'The highest prime computed: ' @.# " (under the limit of " limit').'
|
||||
say /* [↓] define where 1st K─prime is odd*/
|
||||
d.=0; d.2= 2; d.3 = 4; d.4 = 7; d.5 = 13; d.6 = 22; d.7 = 38; d.8=63
|
||||
d.9=102; d.10=168; d.11=268; d.12=426; d.13=673; d.14=1064
|
||||
d!=0
|
||||
do m=1 for K; d!=max(d!,d.m) /*generate & assign 1st K─almost prime.*/
|
||||
mr=right(m,w); mm=m-1
|
||||
|
||||
$=; do #=1 to min(N, d!) /*assign some doubled K─almost primes. */
|
||||
$=$ d.mm.# * 2
|
||||
end /*#*/
|
||||
#=#-1
|
||||
if m==1 then from=2
|
||||
else from=1 + word($, words($) )
|
||||
|
||||
do j=from until #==N /*process an K─almost prime N times.*/
|
||||
if factr()\==m then iterate /*not the correct K─almost prime? */
|
||||
#=#+1; $=$ j /*bump K─almost counter; append it to $*/
|
||||
end /*j*/ /* [↑] generate N K─almost primes.*/
|
||||
|
||||
if nn>0 then say mr"─almost ("N') primes:' $
|
||||
else say ' the last' mr "K─almost prime: " word($, words($))
|
||||
/* [↓] assign K─almost primes.*/
|
||||
do q=1 for #; d.m.q=word($,q) ; end /*q*/
|
||||
do q=1 for #; if d.m.q\==d.mm.q*2 then leave; end /*q*/
|
||||
/* [↑] count doubly-duplicates*/
|
||||
/*──── say copies('─',40) 'for ' m", " q-1 'numbers were doubly─duplicated.' ────*/
|
||||
/*──── say ────*/
|
||||
end /*m*/ /* [↑] display a line for each K─prime*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
factr: if #.j\==. then return #.j
|
||||
z=j; do f=0 while z// 2==0; z=z% 2; end /*÷ by 2*/
|
||||
do f=f while z// 3==0; z=z% 3; end /*÷ " 3*/
|
||||
do f=f while z// 5==0; z=z% 5; end /*÷ " 5*/
|
||||
do f=f while z// 7==0; z=z% 7; end /*÷ " 7*/
|
||||
do f=f while z//11==0; z=z%11; end /*÷ " 11*/
|
||||
do f=f while z//13==0; z=z%13; end /*÷ " 13*/
|
||||
do f=f while z//17==0; z=z%17; end /*÷ " 17*/
|
||||
do f=f while z//19==0; z=z%19; end /*÷ " 19*/
|
||||
|
||||
do i=9 while @.i<=z; d=@.i /*divide by some higher primes. */
|
||||
do f=f while z//d==0; z=z%d; end /*is Z divisible by the prime D ? */
|
||||
end /*i*/ /* [↑] find all factors in Z. */
|
||||
|
||||
if f==0 then f=1; #.j=f; return f /*Is prime (f≡0)? Then return unity. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
genPrimes: arg x; @.=; @.1=2; @.2=3; #.=.; #=2; s.#=@.#**2
|
||||
do j=@.# +2 by 2 to x /*only find odd primes from here on. */
|
||||
do p=2 while s.p<=j /*divide by some known low odd primes. */
|
||||
if j//@.p==0 then iterate j /*Is J divisible by X? Then ¬ prime.*/
|
||||
end /*p*/ /* [↓] a prime (J) has been found. */
|
||||
#=#+1; @.#=j; #.j=1; s.#=j*j /*bump prime count, and also assign ···*/
|
||||
end /*j*/ /* ··· the # of factors, prime, prime².*/
|
||||
return /* [↑] not an optimal prime generator.*/
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
/*REXX program computes and displays the first N K─almost primes from 1 ── ►K. */
|
||||
parse arg N K . /*get optional arguments from the C.L. */
|
||||
if N=='' | N=="," then N=10 /*N not specified? Then use default.*/
|
||||
if K=='' | K=="," then K= 5 /*K " " " " " */
|
||||
/*W: is the width of K, used for output*/
|
||||
do m=1 for K; $=2**m; fir=$ /*generate & assign 1st K─almost prime.*/
|
||||
#=1; if #==N then leave /*#: K─almost primes; Enough are found?*/
|
||||
#=2; $=$ 3*(2**(m-1)) /*generate & append 2nd K─almost prime.*/
|
||||
if #==N then leave /*#: K─almost primes; Enough are found?*/
|
||||
if m==1 then _=fir+fir /* [↓] gen & append 3rd K─almost prime*/
|
||||
else do; _=9*(2**(m-2)); #=3; $=$ _; end
|
||||
do j=_+m-1 until #==N /*process an K─almost prime N times.*/
|
||||
if #factr()\==m then iterate /*not the correct K─almost prime? */
|
||||
#=#+1; $=$ j /*bump K─almost counter; append it to $*/
|
||||
end /*j*/ /* [↑] generate N K─almost primes.*/
|
||||
say right(m, length(K))"─almost ("N') primes:' $
|
||||
end /*m*/ /* [↑] display a line for each K─prime*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
#factr: z=j; do f=0 while z//2==0; z=z%2; end /*divisible by 2. */
|
||||
do f=f while z//3==0; z=z%3; end /*divisible " 3. */
|
||||
do f=f while z//5==0; z=z%5; end /*divisible " 5. */
|
||||
do f=f while z//7==0; z=z%7; end /*divisible " 7. */
|
||||
do i=11 by 6 while i<=z /*insure I isn't divisible by three. */
|
||||
parse var i '' -1 _ /*obtain the right─most decimal digit. */
|
||||
/* [↓] fast check for divisible by 5. */
|
||||
if _\==5 then do; do f=f+1 while z//i==0; z=z%i; end; f=f-1; end /*divisible by I. */
|
||||
if _==3 then iterate /*fast check for X divisible by five.*/
|
||||
x=i+2; do f=f+1 while z//x==0; z=z%x; end; f=f-1 /*divisible by X. */
|
||||
end /*i*/ /* [↑] find all the factors in Z. */
|
||||
|
||||
return max(f, 1) /*if prime (f==0), then return unity.*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue