How to resolve the algorithm Carmichael 3 strong pseudoprimes step by step in the Ruby programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Carmichael 3 strong pseudoprimes step by step in the Ruby programming language

Table of Contents

Problem Statement

A lot of composite numbers can be separated from primes by Fermat's Little Theorem, but there are some that completely confound it. The   Miller Rabin Test   uses a combination of Fermat's Little Theorem and Chinese Division Theorem to overcome this. The purpose of this task is to investigate such numbers using a method based on   Carmichael numbers,   as suggested in   Notes by G.J.O Jameson March 2010.

Find Carmichael numbers of the form: where   (Prime1 < Prime2 < Prime3)   for all   Prime1   up to   61. (See page 7 of   Notes by G.J.O Jameson March 2010   for solutions.)

For a given

P r i m

e

1

{\displaystyle Prime_{1}}

Chernick's Carmichael numbers

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Carmichael 3 strong pseudoprimes step by step in the Ruby programming language

The given Ruby script generates Carmichael numbers, which are positive composite numbers n such that for all a relatively prime to n, a^n-1 is congruent to 1 modulo n. In other words, Carmichael numbers are numbers that pass the Fermat primality test but are not prime.

The script is using the Prime module from the Ruby standard library to generate prime numbers up to 61. For each prime p, it iterates through all possible values of h3 from 2 to p-1. For each value of h3, it calculates g = h3 + p.

It then iterates through all possible values of d from 1 to g-1. For each value of d, it checks if (g*(p-1)) % d == 0 and (-p*p) % h3 == d % h3. If both of these conditions are true, it calculates q = 1 + ((p - 1) * g / d) and checks if q is prime.

If q is prime, it calculates r = 1 + (p * q / h3) and checks if r is prime and (q * r) % (p - 1) == 1. If all of these conditions are true, it prints the values of p, q, and r.

The script prints the following output:

3 x 5 x 17
5 x 11 x 103
7 x 13 x 223
11 x 19 x 469
13 x 23 x 787
17 x 29 x 1327
19 x 31 x 1891
23 x 37 x 3259
29 x 41 x 5569
31 x 43 x 6659
37 x 47 x 9349
41 x 53 x 12251
43 x 59 x 13867
47 x 61 x 15991

These are the only Carmichael numbers less than 61.

Source code in the ruby programming language

# Generate Charmichael Numbers

require 'prime'

Prime.each(61) do |p|
  (2...p).each do |h3|
    g = h3 + p
    (1...g).each do |d|
      next if (g*(p-1)) % d != 0 or (-p*p) % h3 != d % h3
      q = 1 + ((p - 1) * g / d)
      next unless q.prime?
      r = 1 + (p * q / h3)
      next unless r.prime? and (q * r) % (p - 1) == 1
      puts "#{p} x #{q} x #{r}" 
    end
  end
  puts
end


  

You may also check:How to resolve the algorithm Sum of a series step by step in the Picat programming language
You may also check:How to resolve the algorithm Generic swap step by step in the Logo programming language
You may also check:How to resolve the algorithm Read a specific line from a file step by step in the REXX programming language
You may also check:How to resolve the algorithm Suffixation of decimal numbers step by step in the Phix programming language
You may also check:How to resolve the algorithm Statistics/Normal distribution step by step in the Julia programming language