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

→‎{{header|Wren}}: Despite obtaining the correct answers, the previous solution was unsafe for n > 208063.
(→‎{{header|Wren}}: Despite obtaining the correct answers, the previous solution was unsafe for n > 208063.)
Line 246:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-long}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascript">import "./math" for Int, Nums
import "./long" for ULong, ULongs
import "./fmt" for Fmt
 
Line 253 ⟶ 255:
var count = 0
var n = 1
var ln
var maxSafe = Num.maxSafeInteger.cbrt.floor
System.print("First 50 numbers which are the cube roots of the products of their proper divisors:")
while (true) {
var pd = Int.properDivisors(n)
if ((n <= maxSafe && Nums.prod(pd) == n * n * n) {||
(ULongs.prod(pd.map { |f| ULong.new(f) }) == (ln = ULong.new(n)) * ln * ln )) {
count = count + 1
if (count <= 50) {
Line 266 ⟶ 271:
Fmt.print("5,000th : $,d", n)
} else if (count == 50000) {
Fmt.print("50,000th: $,d", n)
break
}
9,490

edits