Perfect totient numbers: Difference between revisions
Content deleted Content added
→{{header|zkl}}: added code |
m →{{header|REXX}}: optimized the PHI function. |
||
Line 122: | Line 122: | ||
@.=. /*memoization array of totient numbers.*/ |
@.=. /*memoization array of totient numbers.*/ |
||
$= /*list of the perfect totient numbers. */ |
$= /*list of the perfect totient numbers. */ |
||
do j=3 until p==N; s= phi(j) |
do j=3 until p==N; s= phi(j) /*obtain totient number for a number. */ |
||
a= s /* [↓] search for a perfect totient #.*/ |
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? */ |
if s\==j then iterate /*Is J not a perfect totient number? */ |
||
p= p + 1 /*bump count of perfect totient numbers*/ |
p= p + 1 /*bump count of perfect totient numbers*/ |
||
Line 135: | Line 135: | ||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
gcd: parse arg x,y; |
gcd: parse arg x,y; do until y==0; parse value x//y y with y x; end /*until*/ |
||
end /*until*/ |
|||
return x |
return x |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
phi: procedure expose @.; parse arg z; if @.z\==. then return @.z |
phi: procedure expose @.; parse arg z; if @.z\==. then return @.z /*was found before?*/ |
||
#= z==1; |
#= z==1; do m=1 for z-1; if gcd(m, z)==1 then #= # + 1; end /*m*/ |
||
end /*m*/ |
|||
@.z= #; return # /*use memoization. */</lang> |
@.z= #; return # /*use memoization. */</lang> |
||
{{out|output|text= when using the default input of : <tt> 20 </tt>}} |
{{out|output|text= when using the default input of : <tt> 20 </tt>}} |