Perfect totient numbers: Difference between revisions
Content added Content deleted
imported>Maxima enthusiast No edit summary |
m (→{{header|Wren}}: Now uses totient method in Math.module.) |
||
Line 2,896: | Line 2,896: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
{{libheader|Wren-math}} |
|||
The version using Euler's product formula. |
The version using Euler's product formula. |
||
<syntaxhighlight lang=" |
<syntaxhighlight lang="wren">import "./math" for 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 = [] |
var perfect = [] |
||
Line 2,918: | Line 2,906: | ||
var sum = 0 |
var sum = 0 |
||
while (tot != 1) { |
while (tot != 1) { |
||
tot = |
tot = Int.totient(tot) |
||
sum = sum + tot |
sum = sum + tot |
||
} |
} |