How to resolve the algorithm Pierpont primes step by step in the M2000 Interpreter programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pierpont primes step by step in the M2000 Interpreter programming language

Table of Contents

Problem Statement

A Pierpont prime is a prime number of the form: 2u3v + 1 for some non-negative integers u and v .

A Pierpont prime of the second kind is a prime number of the form: 2u3v - 1 for some non-negative integers u and v .

The term "Pierpont primes" is generally understood to mean the first definition, but will be called "Pierpont primes of the first kind" on this page to distinguish them.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Pierpont primes step by step in the M2000 Interpreter programming language

Source code in the m2000 programming language

Module Pierpoint_Primes {
      Form 80
      Set Fast !
      const NPP=50
      dim pier(1 to 2, 1 to NPP), np(1 to 2) = 0
      def long x = 1, j
      while np(1)<=NPP or np(2)<=NPP
          x++
          j = @is_pierpont(x)
          if j>0 Else Continue
          if j mod 2 = 1 then np(1)++ :if np(1) <= NPP then pier(1, np(1)) = x
          if j > 1 then np(2)++ : if np(2) <= NPP then pier(2, np(2)) = x
      end while
      
      print "First ";NPP;" Pierpont primes of the first kind:"
      for j = 1 to NPP
          print pier(2, j),
      next j
      if pos>0 then print
      print "First ";NPP;" Pierpont primes of the second kind:"
      for j = 1 to NPP
          print pier(1, j),
      next j
      if pos>0 then print
      Set Fast
      function is_prime(n as decimal)
          if n < 2 then = false  : exit function
          if n <4 then = true : exit function
          if n mod 2 = 0 then = false : exit function
          local i as long
          for i = 3 to int(sqrt(n))+1 step 2
              if n mod i = 0 then = false  : exit function
          next i
          = true
      end function
       
      function is_23(n as long)
          while n mod 2 = 0
              n = n div 2
          end while
          while n mod 3 = 0
              n = n div 3
          end while
          if n = 1 then = true else = false
      end function
       
      function is_pierpont(n as long)
          if not @is_prime(n) then = 0& : exit function 'not prime
          Local p1 = @is_23(n+1), p2 = @is_23(n-1)
          if p1 and p2 then = 3  : exit function      'pierpont prime of both kinds
          if p1 then = 1 : exit function              'pierpont prime of the 1st kind
          if p2 then = 2 : exit function              'pierpont prime of the 2nd kind
          = 0                         'prime, but not pierpont
      end function
}
Pierpoint_Primes

  

You may also check:How to resolve the algorithm Function composition step by step in the Fortress programming language
You may also check:How to resolve the algorithm Factors of an integer step by step in the Sather programming language
You may also check:How to resolve the algorithm Move-to-front algorithm step by step in the Quackery programming language
You may also check:How to resolve the algorithm Universal Turing machine step by step in the zkl programming language
You may also check:How to resolve the algorithm Case-sensitivity of identifiers step by step in the EasyLang programming language