Jump to content

Numbers whose count of divisors is prime: Difference between revisions

Added AppleScript.
(Add PARI/GP implementation)
(Added AppleScript.)
Line 161:
73441 76729 78961 80089 83521 85849 94249 96721 97969
</pre>
 
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">on countFactors(n) -- Positive ns only.
if (n < 4) then return 2 - ((n = 1) as integer)
set factorCount to 2
set sqrt to n ^ 0.5
set limit to sqrt div 1
if (limit = sqrt) then
set factorCount to 3
set limit to limit - 1
end if
repeat with i from 2 to limit
if (n mod i = 0) then set factorCount to factorCount + 2
end repeat
return factorCount
end countFactors
 
on join(lst, delim)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set txt to lst as text
set AppleScript's text item delimiters to astid
return txt
end join
 
on task()
set limit to 100000 - 1
set maxLen to (count (limit as text))
set inset to " "'s text 1 thru (maxLen - 1)
set output to {"Positive integers < " & (limit + 1) & " whose divisor count is an odd prime:"}
set row to {}
set counter to 0
repeat with n from 2 to (limit ^ 0.5) div 1
set sq to n * n
if (countFactors(countFactors(sq)) = 2) then
set counter to counter + 1
set row's end to (inset & sq)'s text -maxLen thru -1
if ((count row) = 10) then
set output's end to join(row, " ")
set row to {}
end if
end if
end repeat
if (row ≠ {}) then set output's end to join(row, " ")
set output's end to linefeed & counter & " such integers"
return join(output, linefeed)
end task
 
task()</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">"Positive integers < 100000 whose divisor count is an odd prime:
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
 
79 such integers"</syntaxhighlight>
 
=={{header|Arturo}}==
557

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.