How to resolve the algorithm Attractive numbers step by step in the Comal programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Attractive numbers step by step in the Comal programming language

Table of Contents

Problem Statement

A number is an   attractive number   if the number of its prime factors (whether distinct or not) is also prime.

The number   20,   whose prime decomposition is   2 × 2 × 5,   is an   attractive number   because the number of its prime factors   (3)   is also prime.

Show sequence items up to   120.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Attractive numbers step by step in the Comal programming language

Source code in the comal programming language

0010 FUNC factors#(n#) CLOSED
0020   count#:=0
0030   WHILE n# MOD 2=0 DO n#:=n# DIV 2;count#:+1
0040   fac#:=3
0050   WHILE fac#<=n# DO
0060     WHILE n# MOD fac#=0 DO n#:=n# DIV fac#;count#:+1
0070     fac#:+2
0080   ENDWHILE
0090   RETURN count#
0100 ENDFUNC factors#
0110 //
0120 ZONE 4
0130 seen#:=0
0140 FOR i#:=2 TO 120 DO
0150   IF factors#(factors#(i#))=1 THEN
0160     PRINT i#,
0170     seen#:+1
0180     IF seen# MOD 18=0 THEN PRINT
0190   ENDIF
0200 ENDFOR i#
0210 PRINT
0220 END


  

You may also check:How to resolve the algorithm Huffman coding step by step in the Picat programming language
You may also check:How to resolve the algorithm Leap year step by step in the Objeck programming language
You may also check:How to resolve the algorithm Happy numbers step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Knapsack problem/Continuous step by step in the Befunge programming language
You may also check:How to resolve the algorithm Tokenize a string with escaping step by step in the 11l programming language