Fasten the solution to 10 in bash by halving the tested integers
This commit is contained in:
parent
ed772e7550
commit
f925e1c86c
1 changed files with 5 additions and 3 deletions
|
@ -1,10 +1,12 @@
|
||||||
#!/usr/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# I have yet to see this script coming to an end...
|
# I have yet to see this script coming to an end...
|
||||||
|
|
||||||
declare -i primeSum=0
|
declare -i primeSum=2
|
||||||
|
sequence=$(seq 3 2 2000000)
|
||||||
|
|
||||||
for num in {2..2000000}; do
|
for num in $sequence; do
|
||||||
|
echo $num
|
||||||
[[ "$(factor $num | cut -d " " -f2)" != $num ]] || primeSum=$(( $primeSum + $num ))
|
[[ "$(factor $num | cut -d " " -f2)" != $num ]] || primeSum=$(( $primeSum + $num ))
|
||||||
done
|
done
|
||||||
echo "$primeSum"
|
echo "$primeSum"
|
||||||
|
|
Reference in a new issue