How to resolve the algorithm Carmichael 3 strong pseudoprimes step by step in the C programming language
How to resolve the algorithm Carmichael 3 strong pseudoprimes step by step in the C 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 C programming language
This C code finds Carmichael numbers that satisfy specific mathematical properties. Carmichael numbers are composite numbers that behave like prime numbers under certain modular arithmetic operations. The code uses a nested loop to generate and test Carmichael numbers within a specified range.
Here's a detailed breakdown of the code:
-
Header File and Macro:
- The code includes the
<stdio.h>
header file for input and output. - It defines a macro
mod(n, m)
that calculates the remainder ofn
divided bym
while ensuring that the result is positive, even for negativen
values.
- The code includes the
-
is_prime()
Function:- This function checks if a given positive integer
n
is prime or not. - It uses a series of conditions to efficiently handle small values and prime numbers that are multiples of 2 or 3.
- For larger numbers, it uses a loop to check for divisibility by potential factors.
- This function checks if a given positive integer
-
carmichael3()
Function:- This function searches for Carmichael numbers with three prime factors
p1
,p2
, andp3
that satisfy certain properties. - It iterates through potential values of
h3
andd
to find triples that meet the conditions outlined in the loop. - If it finds a valid triple, it calculates
p2
andp3
and checks if they are prime. - Finally, it prints the Carmichael number sequence
p1
,p2
, andp3
if they satisfy all the conditions.
- This function searches for Carmichael numbers with three prime factors
-
main()
Function:- In the
main
function, the code iterates fromp1 = 2
top1 = 62
and calls thecarmichael3()
function for eachp1
. - This loop finds and prints Carmichael numbers within this range that satisfy the specified properties.
- In the
In summary, this code generates and identifies Carmichael numbers with three prime factors that meet specific mathematical conditions. Carmichael numbers are a curious class of numbers that exhibit properties similar to prime numbers in certain modular arithmetic operations.
Source code in the c programming language
#include <stdio.h>
/* C's % operator actually calculates the remainder of a / b so we need a
* small adjustment so it works as expected for negative values */
#define mod(n,m) ((((n) % (m)) + (m)) % (m))
int is_prime(unsigned int n)
{
if (n <= 3) {
return n > 1;
}
else if (!(n % 2) || !(n % 3)) {
return 0;
}
else {
unsigned int i;
for (i = 5; i*i <= n; i += 6)
if (!(n % i) || !(n % (i + 2)))
return 0;
return 1;
}
}
void carmichael3(int p1)
{
if (!is_prime(p1)) return;
int h3, d, p2, p3;
for (h3 = 1; h3 < p1; ++h3) {
for (d = 1; d < h3 + p1; ++d) {
if ((h3 + p1)*(p1 - 1) % d == 0 && mod(-p1 * p1, h3) == d % h3) {
p2 = 1 + ((p1 - 1) * (h3 + p1)/d);
if (!is_prime(p2)) continue;
p3 = 1 + (p1 * p2 / h3);
if (!is_prime(p3) || (p2 * p3) % (p1 - 1) != 1) continue;
printf("%d %d %d\n", p1, p2, p3);
}
}
}
}
int main(void)
{
int p1;
for (p1 = 2; p1 < 62; ++p1)
carmichael3(p1);
return 0;
}
You may also check:How to resolve the algorithm Loops/While step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Pick random element step by step in the Gambas programming language
You may also check:How to resolve the algorithm Closures/Value capture step by step in the Objeck programming language
You may also check:How to resolve the algorithm Roots of unity step by step in the Raku programming language
You may also check:How to resolve the algorithm Towers of Hanoi step by step in the CLU programming language