Sieve of Eratosthenes

Generate all prime numbers up to n using the Sieve of Eratosthenes algorithm.

Code

Algorithms
seq 2 "$n" | factor | awk -F: 'NF==2 && $2 ~ /^ [0-9]+$/ {print $1}' | jq -Rs 'split("\n") | map(select(. != "") | tonumber)'

Parameters

Upper limit

Server

More Bash Snippets