Jump to content

Perfect totient numbers: Difference between revisions

m
→‎{{header|REXX}}: optimized the PHI function.
(→‎{{header|zkl}}: added code)
m (→‎{{header|REXX}}: optimized the PHI function.)
Line 122:
@.=. /*memoization array of totient numbers.*/
$= /*list of the perfect totient numbers. */
do j=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*/
Line 135:
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 withy x; y end x /*until*/
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; if gcd(m, z)==1 then #= # + 1; (gcd( end /*m, z)==1)*/
end /*m*/
@.z= #; return # /*use memoization. */</lang>
{{out|output|text=&nbsp; when using the default input of : &nbsp; &nbsp; <tt> 20 </tt>}}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.