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



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



See also
 OEIS:A069654


Related tasks
 Sequence: smallest number with exactly n divisors
 Sequence: nth number with exactly n divisors‎‎


 /* FIND THE SMALLEST NUMBER > THE PREVIOUS ONE WITH EXACTLY N DIVISORS */
 
sequence_100H: procedure options                                                (main);
 
/* PROGRAM-SPECIFIC %REPLACE STATEMENTS MUST APPEAR BEFORE THE %INCLUDE AS */
/* E.G. THE CP/M PL/I COMPILER DOESN'T LIKE THEM TO FOLLOW PROCEDURES      */
   /* PL/I                                                                      */
      %replace maxnumber by         15;
   /* PL/M */                                                                   /*
      DECLARE  MAXNUMBER LITERALLY '15';
   /* */
 
/* PL/I DEFINITIONS                                                             */
%include 'pg.inc';
/* PL/M DEFINITIONS: CP/M BDOS SYSTEM CALL AND CONSOLE I/O ROUTINES, ETC. */    /*
   DECLARE BINARY LITERALLY 'ADDRESS', CHARACTER LITERALLY 'BYTE';
   DECLARE FIXED  LITERALLY ' ',       BIT       LITERALLY 'BYTE';
   DECLARE STATIC LITERALLY ' ',       RETURNS   LITERALLY ' ';
   DECLARE FALSE  LITERALLY '0',       TRUE      LITERALLY '1';
   DECLARE HBOUND LITERALLY 'LAST',    SADDR     LITERALLY '.';
   BDOSF: PROCEDURE( FN, ARG )BYTE;
                               DECLARE FN BYTE, ARG ADDRESS; GOTO 5;   END; 
   BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5;   END;
   PRCHAR:   PROCEDURE( C );   DECLARE C BYTE;      CALL BDOS( 2, C ); END;
   PRSTRING: PROCEDURE( S );   DECLARE S ADDRESS;   CALL BDOS( 9, S ); END;
   PRNL:     PROCEDURE;        CALL PRCHAR( 0DH ); CALL PRCHAR( 0AH ); END;
   PRNUMBER: PROCEDURE( N );
      DECLARE N ADDRESS;
      DECLARE V ADDRESS, N$STR( 6 ) BYTE, W BYTE;
      N$STR( W := LAST( N$STR ) ) = '$';
      N$STR( W := W - 1 ) = '0' + ( ( V := N ) MOD 10 );
      DO WHILE( ( V := V / 10 ) > 0 );
         N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
      END; 
      CALL BDOS( 9, .N$STR( W ) );
   END PRNUMBER;
   MODF: PROCEDURE( A, B )ADDRESS;
      DECLARE ( A, B )ADDRESS;
      RETURN( A MOD B );
   END MODF;
   MIN: PROCEDURE( A, B ) ADDRESS; 
      DECLARE  ( A, B ) ADDRESS;
      IF A < B THEN RETURN( A ); ELSE RETURN( B );
   END MIN;
/* END LANGUAGE DEFINITIONS */
 
   /* TASK */
 
   COUNTDIVISORS: PROCEDURE( N )RETURNS /* THE DIVISOR COUNT OF N */            (
                                FIXED BINARY                                    )
                                ;
      DECLARE N                 FIXED BINARY;
      DECLARE ( I, I2, COUNT )  FIXED BINARY;
      COUNT = 0;
      I     = 1;
      I2    = 1;
      DO WHILE( I2 < N );
         IF MODF( N, I ) = 0 THEN COUNT = COUNT + 2;
         I  = I + 1;
         I2 = I * I;
      END;
      IF I2 = N THEN RETURN ( COUNT + 1 ); ELSE RETURN ( COUNT );
   END COUNTDIVISORS ;
 
   DECLARE ( I, NEXT ) FIXED BINARY;
 
   CALL PRSTRING( SADDR( 'THE FIRST $' ) );
   CALL PRNUMBER( MAXNUMBER );
   CALL PRSTRING( SADDR( ' TERMS OF THE SEQUENCE ARE:$' ) );
   NEXT = 1;
   I    = 1;
   DO WHILE( NEXT <= MAXNUMBER );
      IF NEXT = COUNTDIVISORS( I ) THEN DO;
         CALL PRCHAR( ' ' );
         CALL PRNUMBER( I );
         NEXT = NEXT + 1;
      END;
      I = I + 1;
   END;
 
EOF: end sequence_100H;