How to resolve the algorithm Sieve of Eratosthenes step by step in the FutureBasic programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sieve of Eratosthenes step by step in the FutureBasic programming language

Table of Contents

Problem Statement

The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer.

Implement the   Sieve of Eratosthenes   algorithm, with the only allowed optimization that the outer loop can stop at the square root of the limit, and the inner loop may start at the square of the prime just found. That means especially that you shouldn't optimize by using pre-computed wheels, i.e. don't assume you need only to cross out odd numbers (wheel based on 2), numbers equal to 1 or 5 modulo 6 (wheel based on 2 and 3), or similar wheels based on low primes. If there's an easy way to add such a wheel based optimization, implement it as an alternative version.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sieve of Eratosthenes step by step in the FutureBasic programming language

Source code in the futurebasic programming language

window 1, @"Sieve of Eratosthenes", (0,0,720,300)

begin globals
dynamic gPrimes(1) as Boolean
end globals

local fn SieveOfEratosthenes( n as long )
  long i, j
  
  for i = 2 to  n
    for j = i * i to n step i
      gPrimes(j) = _true
    next
    if gPrimes(i) = 0 then print i,
  next i
  kill gPrimes
end fn

fn SieveOfEratosthenes( 100 )

HandleEvents

  

You may also check:How to resolve the algorithm Non-decimal radices/Output step by step in the PHP programming language
You may also check:How to resolve the algorithm Quine step by step in the SNOBOL4 programming language
You may also check:How to resolve the algorithm File modification time step by step in the Tcl programming language
You may also check:How to resolve the algorithm Narcissistic decimal number step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the Zoea programming language