sandy666
07-12-2023, 04:16 AM
In mathematics, a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In other words, a prime number is a number that cannot be formed by multiplying two smaller natural numbers.
For example, the first few prime numbers are 2, 3, 5, 7, 11, 13, and so on. These numbers are divisible only by 1 and themselves.
Prime numbers are of great importance in number theory and have various applications in cryptography, computer science, and other fields. They form the building blocks for the integers and play a fundamental role in many mathematical proofs and algorithms.
ListPrime
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
103
107
109
and so on...
// fxSieveGenerate
let
Source = (pStart as number, pLimit as number) as list =>
let
xList = List.Generate(() => pStart * 2 , each _ < pLimit, each _ + pStart)
in
xList
in
Source
// ListPrime
let
PrimeLimit = 10000,
SieveLimit = Number.Sqrt(PrimeLimit),
Source = fxSieveGenerate(1, PrimeLimit),
SieveNumbers = (parameter as record) as record =>
let
Iterator = parameter[pIterator] + 1,
Sieve = fxSieveGenerate(parameter[pPrimes]{Iterator},PrimeLimit),
NewPrimes = List.RemoveMatchingItems(parameter[pPrimes],Sieve),
AllPrimes =
if NewPrimes{Iterator+1} <= SieveLimit then
@SieveNumbers([pPrimes=NewPrimes,pIterator=Iterator])
else
[pPrimes=NewPrimes,pIterator=Iterator]
in
AllPrimes,
PrimeList = SieveNumbers([pPrimes=Source,pIterator=-1])
in
PrimeList[pPrimes]
For example, the first few prime numbers are 2, 3, 5, 7, 11, 13, and so on. These numbers are divisible only by 1 and themselves.
Prime numbers are of great importance in number theory and have various applications in cryptography, computer science, and other fields. They form the building blocks for the integers and play a fundamental role in many mathematical proofs and algorithms.
ListPrime
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
103
107
109
and so on...
// fxSieveGenerate
let
Source = (pStart as number, pLimit as number) as list =>
let
xList = List.Generate(() => pStart * 2 , each _ < pLimit, each _ + pStart)
in
xList
in
Source
// ListPrime
let
PrimeLimit = 10000,
SieveLimit = Number.Sqrt(PrimeLimit),
Source = fxSieveGenerate(1, PrimeLimit),
SieveNumbers = (parameter as record) as record =>
let
Iterator = parameter[pIterator] + 1,
Sieve = fxSieveGenerate(parameter[pPrimes]{Iterator},PrimeLimit),
NewPrimes = List.RemoveMatchingItems(parameter[pPrimes],Sieve),
AllPrimes =
if NewPrimes{Iterator+1} <= SieveLimit then
@SieveNumbers([pPrimes=NewPrimes,pIterator=Iterator])
else
[pPrimes=NewPrimes,pIterator=Iterator]
in
AllPrimes,
PrimeList = SieveNumbers([pPrimes=Source,pIterator=-1])
in
PrimeList[pPrimes]