Perfect totient numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
Not a robot (talk | contribs) (add Miranda) |
||
Line 1,693: | Line 1,693: | ||
{{out}} |
{{out}} |
||
<pre>{3,9,15,27,39,81,111,183,243,255,327,363,471,729,2187,2199,3063,4359,4375,5571}</pre> |
<pre>{3,9,15,27,39,81,111,183,243,255,327,363,471,729,2187,2199,3063,4359,4375,5571}</pre> |
||
=={{header|Miranda}}== |
|||
<syntaxhighlight lang="miranda">main :: [sys_message] |
|||
main = [Stdout (show (take 20 perfect) ++ "\n")] |
|||
perfect :: [num] |
|||
perfect = [k | k<-[1..]; k = totientsum k] |
|||
totientsum :: num->num |
|||
totientsum = sum . takewhile (>0) . tl . iterate totient |
|||
totient :: num->num |
|||
totient n = #[k | k<-[1..n-1]; n $gcd k = 1] |
|||
gcd :: num->num->num |
|||
gcd a 0 = a |
|||
gcd a b = gcd b (a mod b)</syntaxhighlight> |
|||
{{out}} |
|||
<pre>[3,9,15,27,39,81,111,183,243,255,327,363,471,729,2187,2199,3063,4359,4375,5571]</pre> |
|||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |