Deceptive numbers: Difference between revisions

(→‎UNIX Shell: simplify)
Line 171:
 
/* wheel to skip multiples of 2, 3, and 5 */
w[0] = 24
w[1] = 42
w[2] = 24
w[3] = 42
w[4] = 64
w[5] = 26
w[6] = 62
w[7] = 46
 
for (n = 11p[0]; c != 10; i = (i + 1) % 8) {
if (d(n += w[i]) == 1) {
n
c += 1
}
n += w[i]
}</syntaxhighlight>
{{out}}
Line 1,231 ⟶ 1,230:
 
=={{header|UNIX Shell}}==
Works with [[POSIX]]-compatible shells.
<syntaxhighlight lang="sh">is () {
return "$((!($1)))"
}
 
modpowfermat_test () {
set -- 1 "$@1" "$(($2 - 1))" "$2"
while is "$3 !=> 0"
do
set -- "$(($1 * (($2 ^ 1) * ($3 & 1) ^ 1) % $4))" "$(($2 * $2 % $4))" "$(($3 >> 1))" "$4"
done
echoreturn "$(($1 != 1))"
}
 
set -- "$n"7
c=0 n=7$1
set -- "$n"
while :
do
for w in 4 2 4 2 4 6 2 6
do
n=fermat_test 10 "$((n += w))" && for p
is "$(modpow 10 "$((n - 1))" "$n") == 1" && for p
do
is 'p * p > n' && {
559

edits