Numbers whose count of divisors is prime: Difference between revisions
Content added Content deleted
m (Peak moved page Numbers which count of divisors is prime to Numbers whose count of divisors is prime: "which" is ungrammatical here, "whose" is acceptable and yields a similar title.) |
Catskill549 (talk | contribs) (added AWK) |
||
Line 47: | Line 47: | ||
52441 54289 57121 58081 59049 63001 65536 66049 69169 72361 |
52441 54289 57121 58081 59049 63001 65536 66049 69169 72361 |
||
73441 76729 78961 80089 83521 85849 94249 96721 97969 |
73441 76729 78961 80089 83521 85849 94249 96721 97969 |
||
</pre> |
|||
=={{header|AWK}}== |
|||
<lang AWK> |
|||
# syntax: GAWK -f NUMBERS_WHOSE_COUNT_OF_DIVISORS_IS_PRIME.AWK |
|||
BEGIN { |
|||
start = 2 |
|||
stop = 99999 |
|||
stop2 = 999 |
|||
for (i=start; i*i<=stop; i++) { |
|||
n = count_divisors(i*i) |
|||
if (n>2 && is_prime(n)) { |
|||
printf("%6d%1s",i*i,++count%10?"":"\n") |
|||
if (i*i <= stop2) { |
|||
count2++ |
|||
} |
|||
} |
|||
} |
|||
printf("\nNumbers with odd prime divisor counts %d-%d: %d\n",start,stop2,count2) |
|||
printf("Numbers with odd prime divisor counts %d-%d: %d\n",start,stop,count) |
|||
exit(0) |
|||
} |
|||
function count_divisors(n, count,i) { |
|||
for (i=1; i*i<=n; i++) { |
|||
if (n % i == 0) { |
|||
count += (i == n / i) ? 1 : 2 |
|||
} |
|||
} |
|||
return(count) |
|||
} |
|||
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> |
|||
4 9 16 25 49 64 81 121 169 289 |
|||
361 529 625 729 841 961 1024 1369 1681 1849 |
|||
2209 2401 2809 3481 3721 4096 4489 5041 5329 6241 |
|||
6889 7921 9409 10201 10609 11449 11881 12769 14641 15625 |
|||
16129 17161 18769 19321 22201 22801 24649 26569 27889 28561 |
|||
29929 32041 32761 36481 37249 38809 39601 44521 49729 51529 |
|||
52441 54289 57121 58081 59049 63001 65536 66049 69169 72361 |
|||
73441 76729 78961 80089 83521 85849 94249 96721 97969 |
|||
Numbers with odd prime divisor counts 2-999: 16 |
|||
Numbers with odd prime divisor counts 2-99999: 79 |
|||
</pre> |
</pre> |
||