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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Attractive numbers step by step in the FutureBasic 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 FutureBasic programming language

Source code in the futurebasic programming language

local fn IsPrime( n as NSUInteger ) as BOOL
  NSUInteger i
  
  if ( n < 2 )        then exit fn = NO
  if ( n = 2 )        then exit fn = YES
  if ( n mod 2 == 0 ) then exit fn = NO
  for i = 3 to int(n^.5) step 2
    if ( n mod i == 0 ) then exit fn = NO
  next
end fn = YES

local fn Factors( n as NSInteger ) as NSInteger
  NSInteger count = 0, f = 2
  
  do
    if n mod f == 0 then count++ : n /= f else f++
  until ( f > n )
end fn = count

void local fn AttractiveNumbers( limit as NSInteger )
  NSInteger c = 0, n
  
  printf @"Attractive numbers through %d are:", limit
  for n = 4 to limit
    if fn IsPrime( fn Factors( n ) )
      printf @"%4d \b", n
      c++
      if ( c mod 10 == 0  ) then print
    end if
  next
end fn

fn AttractiveNumbers( 120 )

HandleEvents

  

You may also check:How to resolve the algorithm Sum of a series step by step in the ActionScript programming language
You may also check:How to resolve the algorithm Horner's rule for polynomial evaluation step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Make directory path step by step in the Java programming language
You may also check:How to resolve the algorithm Averages/Mean time of day step by step in the J programming language
You may also check:How to resolve the algorithm Empty string step by step in the AWK programming language