22 lines
310 B
Bash
22 lines
310 B
Bash
#!/usr/bin/env bash
|
|
|
|
read num
|
|
echo
|
|
|
|
nums=()
|
|
for i in `seq 2 $num`; do
|
|
nums+=($i)
|
|
done
|
|
|
|
unset nums[-1]
|
|
|
|
while [ -n "$nums" ]; do
|
|
prime=${nums[0]}
|
|
echo $prime
|
|
nums_=()
|
|
for elem in "${nums[@]}"; do
|
|
[ $(( $elem % $prime )) -eq 0 ] || nums_+=($elem)
|
|
done
|
|
nums=(${nums_[@]})
|
|
done
|