Perfect totient numbers: Difference between revisions

no edit summary
(Added Applesoft BASIC, Chipmunk Basic, Gambas and MSX Basic. Grouping BASIC dialects)
imported>Maxima enthusiast
No edit summary
Line 1,789:
{{out}}
<pre>{3,9,15,27,39,81,111,183,243,255,327,363,471,729,2187,2199,3063,4359,4375,5571}</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
totientseq(n):=block(
[depth:1,L:n],
while totient(L)#1 do (L:totient(L),depth:depth+1),
j:n,
makelist(j:totient(j),depth),
append([n],%%))$
 
perfect_totient_p(n):=if n=1 then false else is(equal(n,apply("+",rest(totientseq(n)))))$
 
/* Function that returns a list of the first len perfect totient numbers */
perfect_totient_count(len):=block(
[i:1,count:0,result:[]],
while count<len do (if perfect_totient_p(i) then (result:endcons(i,result),count:count+1),i:i+1),
result)$
 
/*Test cases */
perfect_totient_count(20);
</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|Miranda}}==