Cousin primes: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed a variable name to reflect it's use.) |
Catskill549 (talk | contribs) |
||
Line 19: | Line 19: | ||
<br><br> |
<br><br> |
||
=={{header|AWK}}== |
|||
<lang AWK> |
|||
# syntax: GAWK -f COUSIN_PRIMES.AWK |
|||
BEGIN { |
|||
start = 1 |
|||
stop = 1000 |
|||
for (i=start; i<=stop; i++) { |
|||
if (is_prime(i) && is_prime(i+4)) { |
|||
printf("%3d:%3d%1s",i,i+4,++count%10?"":"\n") |
|||
} |
|||
} |
|||
printf("\nCousin primes %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> |
|||
3: 7 7: 11 13: 17 19: 23 37: 41 43: 47 67: 71 79: 83 97:101 103:107 |
|||
109:113 127:131 163:167 193:197 223:227 229:233 277:281 307:311 313:317 349:353 |
|||
379:383 397:401 439:443 457:461 463:467 487:491 499:503 613:617 643:647 673:677 |
|||
739:743 757:761 769:773 823:827 853:857 859:863 877:881 883:887 907:911 937:941 |
|||
967:971 |
|||
Cousin primes 1-1000: 41 |
|||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-02-05}} |
{{works with|Factor|0.99 2021-02-05}} |