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

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the J 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 J programming language

Source code in the j programming language

sieve=: 3 :0
 NB. sieve y  returns a vector of y boxes.
 NB. In each box is an array of 2 columns.
 NB. The first column is the factor tally
 NB. and the second column is a number with
 NB. that many factors.
 NB. Rather than factoring, the algorithm
 NB. counts prime seive cell hits.
 NB. The boxes are not ordered by factor tally.
 range=. <. + i.@:|@:-
 tally=. y#0
 for_i.#\tally do.
  j=. }:^:(y<:{:)i * 1 range >: <. y % i
  tally=. j >:@:{`[`]} tally
 end.
 (</.~ {."1) (,. i.@:#)tally
)


  

You may also check:How to resolve the algorithm Least common multiple step by step in the AutoIt programming language
You may also check:How to resolve the algorithm Find the intersection of a line with a plane step by step in the Prolog programming language
You may also check:How to resolve the algorithm Colour pinstripe/Display step by step in the Action! programming language
You may also check:How to resolve the algorithm Symmetric difference step by step in the Amazing Hopper programming language
You may also check:How to resolve the algorithm Fibonacci n-step number sequences step by step in the Tailspin programming language