Numbers which are the cube roots of the product of their proper divisors: Difference between revisions

Added AppleScript.
(Added 11l)
(Added AppleScript.)
Line 103:
50000th: 223735
</pre>
 
=={{header|AppleScript}}==
This too does the "seven proper divisors" test rather than the multiplications, which saves time and avoids products that are too large for AppleScript numbers.
<syntaxhighlight lang="applescript">on properDivisors(n)
set output to {}
if (n > 1) then
set sqrt to n ^ 0.5
set limit to sqrt div 1
if (limit = sqrt) then
set end of output to limit
set limit to limit - 1
end if
repeat with i from limit to 2 by -1
if (n mod i is 0) then
set beginning of output to i
set end of output to n div i
end if
end repeat
set beginning of output to 1
end if
return output
end properDivisors
 
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 output to {"First 50 numbers whose cubes are the products of their proper divisors:"}
set n to 1
set found to 1
set subgroup to {text -5 thru -1 of (" " & n)}
repeat
set n to n + 1
if ((count properDivisors(n)) = 7) then
set found to found + 1
if (found > 5000) then
if (found = 50000) then
set end of output to "50,000th: " & text -6 thru -1 of (" " & n)
exit repeat
end if
else if (found > 500) then
if (found = 5000) then set end of output to " 5,000th: " & text -6 thru -1 of (" " & n)
else if (found > 50) then
if (found = 500) then set end of output to " 500th: " & text -6 thru -1 of (" " & n)
else
set end of subgroup to text -5 thru -1 of (" " & n)
if (found mod 10 = 0) then
set end of output to join(subgroup, "")
set subgroup to {}
end if
end if
end if
end repeat
return join(output, linefeed)
end task
 
task()</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">"First 50 numbers whose cubes are the products of their proper divisors:
1 24 30 40 42 54 56 66 70 78
88 102 104 105 110 114 128 130 135 136
138 152 154 165 170 174 182 184 186 189
190 195 222 230 231 232 238 246 248 250
255 258 266 273 282 285 286 290 296 297
500th: 2526
5,000th: 23118
50,000th: 223735"</syntaxhighlight>
 
=={{header|BASIC}}==
557

edits