How to resolve the algorithm Attractive numbers step by step in the Action! programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Attractive numbers step by step in the Action! 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 Action! programming language
Source code in the action! programming language
INCLUDE "H6:SIEVE.ACT"
BYTE FUNC IsAttractive(BYTE n BYTE ARRAY primes)
BYTE count,f
IF n<=1 THEN
RETURN (0)
ELSEIF primes(n) THEN
RETURN (0)
FI
count=0 f=2
DO
IF n MOD f=0 THEN
count==+1
n==/f
IF n=1 THEN
EXIT
ELSEIF primes(n) THEN
f=n
FI
ELSEIF f>=3 THEN
f==+2
ELSE
f=3
FI
OD
IF primes(count) THEN
RETURN (1)
FI
RETURN (0)
PROC Main()
DEFINE MAX="120"
BYTE ARRAY primes(MAX+1)
BYTE i
Put(125) PutE() ;clear the screen
Sieve(primes,MAX+1)
PrintF("Attractive numbers in range 1..%B:%E",MAX)
FOR i=1 TO MAX
DO
IF IsAttractive(i,primes) THEN
PrintF("%B ",i)
FI
OD
RETURN
You may also check:How to resolve the algorithm Infinity step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Twelve statements step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Remove lines from a file step by step in the J programming language
You may also check:How to resolve the algorithm Fibonacci word step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Singleton step by step in the Wren programming language