Perfect totient numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: optimized the PHI function.)
m (→‎{{header|REXX}}: optimized the main DO loop (twice as fast).)
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) /*obtain totient number for a number. */
do j=3 by 2 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
do until a==1; a= phi(a); s= s + a
end /*until*/
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*/