Perfect totient numbers: Difference between revisions

Content added Content deleted
(Added Sidef)
m (→‎{{header|REXX}}: added the REXX computer programming language.)
Line 110:
{{out}}
<pre>[3, 9, 15, 27, 39, 81, 111, 183, 243, 255, 327, 363, 471, 729, 2187, 2199, 3063, 4359, 4375, 5571]</pre>
 
=={{header|REXX}}==
<lang rexx>/*REXX program calculates and displays the first N perfect totient numbers. */
parse arg N . /*obtain optional argument from the CL.*/
if N=='' | N=="," then N= 25 /*Not specified? Then use the default.*/
p= 0 /*the count of perfect totient numbers.*/
@.=. /*memoization array of totient numbers.*/
$= /*list of the perfect totient numbers. */
do j=3 by 3 until p==N; s= phi(j) /*obtain totient number for a number. */
a= s /* [↓] search for a perfect totient #.*/
do until a==1; a= phi(a); s= s + a
end /*until*/
if s\==j then iterate /*Is J not a perfect totient number? */
p= p + 1 /*bump count of perfect totient numbers*/
$= $ j /*add to perfect totient numbers list. */
end /*j*/
 
say 'The first ' N " perfect totient numbers:" /*display the header to the terminal. */
say strip($) /* " " list. " " " */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
gcd: parse arg x,y; do until y==0; parse value x//y y with y x
end /*until*/
return x
/*──────────────────────────────────────────────────────────────────────────────────────*/
phi: procedure expose @.; parse arg z; if @.z\==. then return @.z /*was found before?*/
#= z==1; do m=1 for z-1; #= # + (gcd(m, z)==1)
end /*m*/
@.z= #; return # /*use memoization. */</lang>
{{out|output|text=&nbsp; when using the default input of : &nbsp; &nbsp; <tt> 25 </tt>}}
<pre>
The first 25 perfect totient numbers:
3 9 15 27 39 81 111 183 243 255 327 363 471 729 2187 2199 3063 4359 4375 5571
</pre>
 
=={{header|Sidef}}==