Carmichael Numbers in JavaIn this section, we will learn what is Carmichael number and also create Java programs to check if the given number is a Carmichael number or not. The Carmichael numbers program is frequently asked in Java coding interviews and academics. Carmichael NumbersA composite number n that are pseudoprimes to every base 'a' i.e. a^{n1}≡ 1(mod n) for all integer 'a' with GCD(a, n)=1 are called absolute pseudoprime or Carmichael numbers. The number must satisfy the necessary and sufficient conditions for Carmichael numbers. n is absolute pseudoprime or Carmichael number if:
They are extremely rare. Note that every Carmichael number is the product of at least three distinct primes. In other words, we can say that a composite number n is a Carmichael number if whenever a relatively prime to 'n', we have:
a^{n1}≡1(mod n)
Let's see how to calculate Carmichael number. Example of Carmichael NumbersLet's check 561 is a Carmichael number or not. If the number satisfies the above two conditions, it means 561 is a Carmichael number.
Let, GCD (a, 561) = 1 Claim: a^{560} ≡ 1 mod 561
a^{2}≡ 1 mod 3
a^{10}≡ 1 mod 11 a^{16}≡ 1 mod 17 Suppose, 'a' that is relatively prime to 561. So, a is not a multiple of 3 or 11 or 17. Now despite the fact that 561 is not prime it still satisfies the conclusion of the formal theorem we are going to show that 'a' raised to the power of 560 is congruent to 1 modulo 561. Now 3, 11, and 17 are prime numbers, and consequently by formosanal theorem, 'a' square is congruent to 1 modulo 3 'a' to the 10^{th} power is congruent to 1 modulo 11, and 'a' to the 16^{th} power is congruent to 1 modulo 17. Now we will take the first congruence, 'a' square is congruent to 1 modulo 3 and we will raise both sides the power to conclude that 'a' to the 80^{th} power is congruent to 1 modulo 3. We can do the same thing with the next congruence. We can take 'a' to the power 10^{th} power is congruent to 1 modulo 11 and raise both sides to the eight power to calculate that 'a' to the 80^{th} power is congruent to 1 modulo 11 and finally we can take that last congruence 'a' to the 16^{th} is congruent to 1 modulo 17 and we can raise both sides to the fifth power in order to calculate that 'a' to the 80^{th} power is congruent to 1 modulo 17.
(a^{2})^{40}≡ 1 mod 3
(a^{10})^{8}≡ 1 mod 11 (a^{16})^{5}≡ 1 mod 17 Now, we will combine all together using the Chinese Remainder Theorem (CRT). We know that 'a' to the 80^{th} power is 1 modulo 3, 11, and 17. So, we can conclude that 'a' to the 80^{th} power is 1 modulo 561. Therefore, by CRT:
a^{80}=1 mod 561
We are going to perform one more step here is that take 'a' to the 80^{th} congruent to 1 modulo 561. Raise both sides to the 7^{th} power, we found that 'a' to the 560 is congruent to 1 modulo 561. Therefore,
(a^{80})^{7}=a^{560}≡ 1 mod 561
So, despite the fact that 561 is not a prime number it still satisfies the conclusion of hermozilla theorem (whenever 'a' is relatively prime to n then a to the n minus first power is congruent to one modulo n). First few Carmichael numbers are 561, 1105, 1729, 2465, 2821, 6601, 8911, 10585, 15841. Algorithm
Carmichael Numbers Java ProgramCheckCarmichaelNumber.java Output 1: Enter the Number: 10585 10585 is a Carmichael number. Output 2: Enter the Number: 564 564 is not a Carmichael number.
Next TopicContextual Keywords in Java
