Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
14
Task/Almost-prime/Mathematica/almost-prime.math
Normal file
14
Task/Almost-prime/Mathematica/almost-prime.math
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
kprimes[k_,n_] :=
|
||||
(* generates a list of the n smallest k-almost-primes *)
|
||||
Module[{firstnprimes, runningkprimes = {}},
|
||||
firstnprimes = Prime[Range[n]];
|
||||
runningkprimes = firstnprimes;
|
||||
Do[
|
||||
runningkprimes =
|
||||
Outer[Times, firstnprimes , runningkprimes ] // Flatten // Union // Take[#, n] & ;
|
||||
(* only keep lowest n numbers in our running list *)
|
||||
, {i, 1, k - 1}];
|
||||
runningkprimes
|
||||
]
|
||||
(* now to create table with n=10 and k ranging from 1 to 5 *)
|
||||
Table[Flatten[{"k = " <> ToString[i] <> ": ", kprimes[i, 10]}], {i,1,5}] // TableForm
|
||||
Loading…
Add table
Add a link
Reference in a new issue