How to resolve the algorithm Sequence of non-squares step by step in the ALGOL W programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sequence of non-squares step by step in the ALGOL W programming language

Table of Contents

Problem Statement

Show that the following remarkable formula gives the sequence of non-square natural numbers:

This is sequence   A000037   in the OEIS database.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sequence of non-squares step by step in the ALGOL W programming language

Source code in the algol programming language

begin
    % check values of the function: f(n) = n + floor(1/2 + sqrt(n))    %
    % are not squares                                                  %

    integer procedure f ( integer value n ) ;
        begin
            n + entier( 0.5 + sqrt( n ) )
        end f ;

    logical noSquares;

    % first 22 values of f                                             %
    for n := 1 until 22 do writeon( i_w := 1, f( n ) );

    % check f(n) does not produce a square for n in 1..1 000 000       %
    noSquares := true;
    for n := 1 until 1000000 do begin
        integer fn, rn;
        fn := f( n );
        rn := round( sqrt( fn ) );
        if ( rn * rn ) = fn then begin
            write( "Found square at: ", n );
            noSquares := false
        end if_fn_is_a_square 
    end for_n ;

    if noSquares then write( "f(n) did not produce a square in 1 .. 1 000 000" )
                 else write( "f(n) produced a square" )

end.

  

You may also check:How to resolve the algorithm One-dimensional cellular automata step by step in the J programming language
You may also check:How to resolve the algorithm Strip control codes and extended characters from a string step by step in the langur programming language
You may also check:How to resolve the algorithm Sort an array of composite structures step by step in the Swift programming language
You may also check:How to resolve the algorithm Combinations step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Read entire file step by step in the VBScript programming language