Sophie Germain Prime


Prime numbers are those numbers that are greater than one and they simply have two factors: the number itself and factor 1. This indicates that no number apart from 1 as well as the number itself could be used to divide these numbers without leaving a residue. For instance, the first ten prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29. If we take the number 2, the factors are 2 and 1. That is the number itself and the factor 1. Similarly, if we take 11, the factors are 11 and 1. That is the number itself and the factor 1. Now that we have gotten a clear idea of what prime numbers are, it's time for us to move on to our key topic which is Sophie Germain Prime numbers.

So what exactly are Sophie Germain Prime numbers?

A prime number p is said to be a Sophie Germain prime in number theory, which is the study of integers and arithmetic functions if 2p + 1 is also a prime number.

2, 3, 5, 11, 23, 29, 41, 53, 83, 89, 113, 131, 173, 179, 191, 233, 239, 251, 281, 293, 359 and so on. These are the initial Sophie Germain primes.

Problem Statement

Implement a program to print Sophie Germain prime numbers.

Approach

We first take the number and check whether it is a prime number or not. That is whether the factors of that number are 1 and that number itself. If it is a prime number, we move forward to the next step. That is, we multiply the number by 2 and add 1 to it. The result obtained is taken and we check whether the result is a prime number or not. If both the conditions apply well and if in both cases the number obtained is prime. Then the number is a Sophie Germain Prime number.

Example 1

Let p=2 which is a prime number and 2p+1 = (2*2) + 1 which equals 5. Since 2 and 5 are both prime numbers, 2 is said to be a Sophie Germain prime.

Example 2

Similarly, let p=3 which is a prime number, and 2p+1 = (2*3) + 1 which equals 7. Since 2 and 7 are both prime numbers, 3 is said to be a Sophie Germain prime.

Example 3

Let us take another example; say p=7 which is a prime number and 2p+1 = (2*7) + 1 which equals 15. Since 15 is not a prime number, 7 cannot be a Sophie Germain prime.

C program to print Sophie Germain prime.

Example

#include<stdio.h>
#include <stdbool.h>
#include <string.h>
// function to detect prime number sieve method is used to check whether the number is prime or not.
bool sieve(int n, bool primeNum[]) {
   for (int p = 2; p * p <= n; p++) {
       // If prime[p] is not changed, then it is a prime
   if (primeNum[p] == true) {
      // Update all multiples of p
      for (int i = p * 2; i <= n; i += p)
      primeNum[i] = false;
    }
  }
}
void SophieGermainPrime(int n) {
   bool primeNum[2 * n + 1];
   memset(primeNum, true, sizeof(primeNum));
   sieve(2 * n + 1, primeNum);
   for (int i = 2; i <= n; ++i) {
      // checking each i if it is Sophie germain prime or not.
      if (primeNum[i] && primeNum[2 * i + 1])
      printf("%d ",i);
    }
}
int main() {
   int n = 50;
   printf("Sophie Germain Primes below 50: ");
   SophieGermainPrime(n);
   return 0;
}

Output

On execution, it will produce the following output:

Sophie Germain Primes below 50: 2 3 5 11 23 29 41

Conclusion

Likewise, we can determine whether the given number is a Sophie Germain prime number or not by inputting the value. The challenge of determining whether the given number is a Sophie Germain prime number or not is resolved in this article. Here C programming codes for the same are provided.

Updated on: 23-Aug-2023

94 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements