用bash找出10000到20000之间的所有质数

#!/bin/bash
for (( i=10000; i<20000; i++ ))
do
    k=$(echo "sqrt($i)" | bc)
    for (( j=2; j<=$k; j++ ))
    do
#        echo "i=$i;j=$j;k=$k"
        [[ $(($i%$j)) -eq 0 ]] && break
    done
    [[ $j -gt $k ]] && echo -n "$i "
done
echo "are prime"

0 Responses to “find prime within a range by using bash”

  1. No Comments

Leave a Reply





文章归档