Prime numbers p for which the sum of primes less than or equal to p is prime: Difference between revisions
Content added Content deleted
(Prime numbers p which sum of prime numbers less or equal to p is prime es FreeBASIC) |
Catskill549 (talk | contribs) (added AWK) |
||
Line 83: | Line 83: | ||
Found 21 prime sums of primes below 1000 |
Found 21 prime sums of primes below 1000 |
||
</pre> |
|||
=={{header|AWK}}== |
|||
<lang AWK> |
|||
# syntax: GAWK -f PRIME_NUMBERS_P_WHICH_SUM_OF_PRIME_NUMBERS_LESS_OR_EQUAL_TO_P_IS_PRIME.AWK |
|||
BEGIN { |
|||
start = 1 |
|||
stop = 999 |
|||
for (i=start; i<=stop; i++) { |
|||
if (is_prime(i)) { |
|||
sum += i |
|||
if (is_prime(sum)) { |
|||
printf("%4d%1s",i,++count%10?"":"\n") |
|||
} |
|||
} |
|||
} |
|||
printf("\n%d-%d: %d\n",start,stop,count) |
|||
exit(0) |
|||
} |
|||
function is_prime(x, i) { |
|||
if (x <= 1) { |
|||
return(0) |
|||
} |
|||
for (i=2; i<=int(sqrt(x)); i++) { |
|||
if (x % i == 0) { |
|||
return(0) |
|||
} |
|||
} |
|||
return(1) |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
2 3 7 13 37 43 281 311 503 541 |
|||
557 593 619 673 683 733 743 839 881 929 |
|||
953 |
|||
1-999: 21 |
|||
</pre> |
</pre> |
||