How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the PL/M programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the PL/M programming language

Table of Contents

Problem Statement

Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.

Show here, on this page, at least the first 15 terms of the sequence.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the PL/M programming language

Source code in the pl/m programming language

100H: /* FIND THE SMALLEST NUMBER > THE PREVIOUS ONE WITH EXACTLY N DIVISORS */

   /* CP/M BDOS SYSTEM CALL */
   BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
   /* CONSOLE OUTPUT ROUTINES */
   PR$CHAR:   PROCEDURE( C ); DECLARE C BYTE;    CALL BDOS( 2, C );  END;
   PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S );  END;
   PR$NL:     PROCEDURE; CALL PR$STRING( .( 0DH, 0AH, '$' ) );       END;
   PR$NUMBER: PROCEDURE( N );
      DECLARE N ADDRESS;
      DECLARE V ADDRESS, N$STR( 6 ) BYTE INITIAL( '.....$' ), W BYTE;
      N$STR( W := LAST( N$STR ) - 1 ) = '0' + ( ( V := N ) MOD 10 );
      DO WHILE( ( V := V / 10 ) > 0 );
         N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
      END;
      CALL PR$STRING( .N$STR( W ) );
   END PR$NUMBER;

   /* TASK */

   /* RETURNS THE DIVISOR COUNT OF N */
   COUNT$DIVISORS: PROCEDURE( N )ADDRESS;
      DECLARE N ADDRESS;
      DECLARE ( I, I2, COUNT ) ADDRESS;
      COUNT = 0;
      I     = 1;
      DO WHILE( ( I2 := I * I ) < N );
         IF N MOD I = 0 THEN COUNT = COUNT + 2;
         I = I + 1;
      END;
      IF I2 = N THEN RETURN ( COUNT + 1 ); ELSE RETURN ( COUNT );
   END COUNT$DIVISORS ;
 
   DECLARE MAX LITERALLY '15';
   DECLARE ( I, NEXT ) ADDRESS;

   CALL PR$STRING( .'THE FIRST $' );
   CALL PR$NUMBER( MAX );
   CALL PR$STRING( .' TERMS OF THE SEQUENCE ARE:$' );
   NEXT = 1;
   I    = 1;
   DO WHILE( NEXT <= MAX );
      IF NEXT = COUNT$DIVISORS( I ) THEN DO;
         CALL PR$CHAR( ' ' );
         CALL PR$NUMBER( I );
         NEXT = NEXT + 1;
      END;
      I = I + 1;
   END;

EOF

  

You may also check:How to resolve the algorithm XML/Input step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Forward difference step by step in the Plain English programming language
You may also check:How to resolve the algorithm HTTPS step by step in the Lingo programming language
You may also check:How to resolve the algorithm Zig-zag matrix step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Fairshare between two and more step by step in the ALGOL 68 programming language