Perfect totient numbers: Difference between revisions

m
→‎{{header|Wren}}: Now uses totient method in Math.module.
imported>Maxima enthusiast
No edit summary
m (→‎{{header|Wren}}: Now uses totient method in Math.module.)
Line 2,896:
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-math}}
The version using Euler's product formula.
<syntaxhighlight lang="ecmascriptwren">varimport totient = Fn".new/math" {for |n|Int
var tot = n
var i = 2
while (i*i <= n) {
if (n%i == 0) {
while(n%i == 0) n = (n/i).floor
tot = tot - (tot/i).floor
}
if (i == 2) i = 1
i = i + 2
}
if (n > 1) tot = tot - (tot/n).floor
return tot
}
 
var perfect = []
Line 2,918 ⟶ 2,906:
var sum = 0
while (tot != 1) {
tot = totientInt.calltotient(tot)
sum = sum + tot
}
9,482

edits