How to resolve the algorithm N-smooth numbers step by step in the PARI/GP programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm N-smooth numbers step by step in the PARI/GP programming language

Table of Contents

Problem Statement

n-smooth   numbers are positive integers which have no prime factors > n. The   n   in the expression   n-smooth   is always prime; there are   no   9-smooth numbers. 1   (unity)   is always included in n-smooth numbers.

2-smooth   numbers are non-negative powers of two. 5-smooth   numbers are also called   Hamming numbers. 7-smooth   numbers are also called   humble numbers.

A way to express   11-smooth   numbers is:

All ranges   (for   n)   are to be inclusive, and only prime numbers are to be used. The (optional) n-smooth numbers for the third range are:   503,   509,   and   521. Show all n-smooth numbers for any particular   n   in a horizontal list. Show all output here on this page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm N-smooth numbers step by step in the PARI/GP programming language

Source code in the pari/gp programming language

Vi__smooth(V0, C)= {
  my( W= #V0, V_r= Vec([1],C), v= V0, ix= vector(W,i,1), t);
  for( c= 2, C
  , V_r[c]= t= vecmin(v);
    for( w= 1, W
    , if( v[w] == t, v[w]= V0[w] * V_r[ ix[w]++ ]);
    );
  );
  V_r;
}
N_smooth(N, C=20, S=1)= Vi__smooth(primes([0,N]),S+C-1)[S..S+C-1];

[print(v) |v<-[N_smooth(N, 25)        |N<-primes([  2, 29])]];
[print(v) |v<-[N_smooth(N,  3,  3000) |N<-primes([  3, 29])]];
[print(v) |v<-[N_smooth(N, 20, 30000) |N<-primes([503,521])]];

  

You may also check:How to resolve the algorithm Matrix digital rain step by step in the Batch File programming language
You may also check:How to resolve the algorithm Abstract type step by step in the J programming language
You may also check:How to resolve the algorithm Singleton step by step in the Oforth programming language
You may also check:How to resolve the algorithm Command-line arguments step by step in the Python programming language
You may also check:How to resolve the algorithm Hilbert curve step by step in the Racket programming language