How to resolve the algorithm Safe primes and unsafe primes step by step in the Smalltalk programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Safe primes and unsafe primes step by step in the Smalltalk programming language
Table of Contents
Problem Statement
Show all output here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Safe primes and unsafe primes step by step in the Smalltalk programming language
Source code in the smalltalk programming language
[
| isSafePrime printFirstNElements |
isSafePrime := [:p | ((p-1)//2) isPrime].
printFirstNElements :=
[:coll :n |
(coll to:n)
do:[:p | Transcript show:p]
separatedBy:[Transcript space]
].
(Iterator on:[:b | Integer primesUpTo:10000000 do:b])
partition:isSafePrime
into:[:savePrimes :unsavePrimes |
|nSaveBelow1M nSaveBelow10M nUnsaveBelow1M nUnsaveBelow10M|
nSaveBelow1M := savePrimes count:[:p | p < 1000000].
nSaveBelow10M := savePrimes size.
nUnsaveBelow1M := unsavePrimes count:[:p | p < 1000000].
nUnsaveBelow10M := unsavePrimes size.
Transcript showCR: 'first 35 safe primes:'.
printFirstNElements value:savePrimes value:35.
Transcript cr.
Transcript show: 'safe primes below 1,000,000: '.
Transcript showCR:nSaveBelow1M printStringWithThousandsSeparator.
Transcript show: 'safe primes below 10,000,000: '.
Transcript showCR:nSaveBelow10M printStringWithThousandsSeparator.
Transcript showCR: 'first 40 unsafe primes:'.
printFirstNElements value:unsavePrimes value:40.
Transcript cr.
Transcript show: 'unsafe primes below 1,000,000: '.
Transcript showCR:nUnsaveBelow1M printStringWithThousandsSeparator.
Transcript show: 'unsafe primes below 10,000,000: '.
Transcript showCR:nUnsaveBelow10M printStringWithThousandsSeparator.
]
] benchmark:'runtime: safe primes'
You may also check:How to resolve the algorithm Take notes on the command line step by step in the Perl programming language
You may also check:How to resolve the algorithm User input/Text step by step in the Modula-3 programming language
You may also check:How to resolve the algorithm Hickerson series of almost integers step by step in the Ruby programming language
You may also check:How to resolve the algorithm Pythagoras tree step by step in the Sidef programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the Pike programming language