The Wayback Machine - https://web.archive.org/web/20240708012026/https://www.geeksforgeeks.org/lemoines-conjecture/
Open In App

Lemoine’s Conjecture

Last Updated : 20 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Any odd integer greater than 5 can be expressed as a sum of an odd prime (all primes other than 2 are odd) and an even semiprime. A semiprime number is a product of two prime numbers. This is called Lemoine’s conjecture. 
Examples :

7 = 3 + (2 × 2), 
where 3 is a prime number (other than 2) and 4 (= 2 × 2) is a semiprime number.
11 = 5 + (2 × 3) 
where 5 is a prime number and 6(= 2 × 3) is a semiprime number.
9 = 3 + (2 × 3) or 9 = 5 + (2 × 2)
47 = 13 + 2 × 17 = 37 + 2 × 5 = 41 + 2 × 3 = 43 + 2 × 2

 Below is the implementation of Lemoine’s Conjecture:

C++




// C++ code to verify Lemoine's Conjecture
// for any odd number >= 7
#include<bits/stdc++.h>
using namespace std;
 
// Function to check if a number is
// prime or not
bool isPrime(int n)
{
    if (n < 2)
        return false;
         
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}
 
// Representing n as p + (2 * q) to satisfy
// lemoine's conjecture
void lemoine(int n)
{
    // Declaring a map to hold pairs (p, q)
    map<int, int> pr;
     
    // Declaring an iterator for map
    map<int, int>::iterator it;
    it = pr.begin();
     
    // Finding various values of p for each q
    // to satisfy n = p + (2 * q)
    for (int q = 1; q <= n / 2; q++)
    {
        int p = n - 2 * q;
         
        // After finding a pair that satisfies the
        // equation, check if both p and q are
        // prime or not
        if (isPrime(p) && isPrime(q))
         
            // If both p and q are prime, store
            // them in the map
            pr.insert(it, pair<int, int>(p, q));
    }
     
    // Displaying all pairs (p, q) that satisfy
    // lemoine's conjecture for the number 'n'
    for (it = pr.begin(); it != pr.end(); ++it)
        cout << n << " = " << it->first
             << " + (2 * " << it->second << ")\n";
}
 
// Driver Function
int main()
{
    int n = 39;
    cout << n << " can be expressed as " << endl;
     
    // Function calling
    lemoine(n);
     
    return 0;
}
 
// This code is contributed by Saagnik Adhikary


Java




// Java code to verify Lemoine's Conjecture
// for any odd number >= 7
 
import java.util.*;
 
class GFG {
    static class pair {
        int first, second;
 
        public pair(int first, int second) {
            this.first = first;
            this.second = second;
        }
    }
 
    // Function to check if a number is
    // prime or not
    static boolean isPrime(int n) {
        if (n < 2)
            return false;
 
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (n % i == 0)
                return false;
        }
        return true;
    }
 
    // Representing n as p + (2 * q) to satisfy
    // lemoine's conjecture
    static void lemoine(int n) {
        // Declaring a map to hold pairs (p, q)
        HashMap<Integer, pair> pr = new HashMap<>();
 
        // Declaring an iterator for map
        // HashMap<Integer,Integer>::iterator it;
        // it = pr.begin();
        int i = 0;
        // Finding various values of p for each q
        // to satisfy n = p + (2 * q)
        for (int q = 1; q <= n / 2; q++) {
            int p = n - 2 * q;
 
            // After finding a pair that satisfies the
            // equation, check if both p and q are
            // prime or not
            if (isPrime(p) && isPrime(q))
 
                // If both p and q are prime, store
                // them in the map
                pr.put(i, new pair(p, q));
            i++;
        }
 
        // Displaying all pairs (p, q) that satisfy
        // lemoine's conjecture for the number 'n'
        for (Map.Entry<Integer, pair> it : pr.entrySet())
            System.out.print(n + " = " + it.getValue().first + " + (2 * " + it.getValue().second + ")\n");
    }
 
    // Driver Function
    public static void main(String[] args) {
        int n = 39;
        System.out.print(n + " can be expressed as " + "\n");
 
        // Function calling
        lemoine(n);
 
    }
}
 
// This code contributed by aashish1995


Python3




# Python code to verify Lemoine's Conjecture
# for any odd number >= 7
from math import sqrt
 
# Function to check if a number is
# prime or not
def isPrime(n: int) -> bool:
    if n < 2:
        return False
 
    for i in range(2, int(sqrt(n)) + 1):
        if n % i == 0:
            return False
 
    return True
 
# Representing n as p + (2 * q) to satisfy
# lemoine's conjecture
def lemoine(n: int) -> None:
 
    # Declaring a map to hold pairs (p, q)
    pr = dict()
 
    # Finding various values of p for each q
    # to satisfy n = p + (2 * q)
    for q in range(1, n // 2 + 1):
        p = n - 2 * q
 
        # After finding a pair that satisfies the
        # equation, check if both p and q are
        # prime or not
        if isPrime(p) and isPrime(q):
 
            # If both p and q are prime, store
            # them in the map
            if p not in pr:
                pr[p] = q
 
    # Displaying all pairs (p, q) that satisfy
    # lemoine's conjecture for the number 'n'
    for it in pr:
        print("%d = %d + (2 * %d)" % (n, it, pr[it]))
 
# Driver Code
if __name__ == "__main__":
    n = 39
    print(n, "can be expressed as ")
 
    # Function calling
    lemoine(n)
 
# This code is contributed by
# sanjeev2552


C#




// C# code to verify Lemoine's Conjecture
// for any odd number >= 7
using System;
using System.Collections.Generic;
 
class GFG
{
    public
   class pair
   {
         public
           int first, second;
 
          public pair(int first, int second)
          {
              this.first = first;
              this.second = second;
          }
      }
 
      // Function to check if a number is
      // prime or not
      static bool isPrime(int n)
      {
          if (n < 2)
              return false;
 
          for (int i = 2; i <= Math.Sqrt(n); i++)
          {
              if (n % i == 0)
                  return false;
          }
          return true;
      }
 
      // Representing n as p + (2 * q) to satisfy
      // lemoine's conjecture
      static void lemoine(int n)
      {
 
          // Declaring a map to hold pairs (p, q)
          Dictionary<int, pair> pr = new Dictionary<int, pair>();
 
          // Declaring an iterator for map
          // Dictionary<int,int>::iterator it;
          // it = pr.begin();
          int i = 0;
 
          // Finding various values of p for each q
          // to satisfy n = p + (2 * q)
          for (int q = 1; q <= n / 2; q++)
          {
              int p = n - 2 * q;
 
              // After finding a pair that satisfies the
              // equation, check if both p and q are
              // prime or not
              if (isPrime(p) && isPrime(q))
 
                  // If both p and q are prime, store
                  // them in the map
                  pr.Add(i, new pair(p, q));
              i++;
          }
 
          // Displaying all pairs (p, q) that satisfy
          // lemoine's conjecture for the number 'n'
          foreach (KeyValuePair<int, pair> it in pr)
              Console.Write(n + " = " + it.Value.first +
                            " + (2 * " + it.Value.second + ")\n");
      }
 
      // Driver code
      public static void Main(String[] args)
      {
          int n = 39;
          Console.Write(n + " can be expressed as " + "\n");
 
          // Function calling
          lemoine(n);
      }
  }
 
  // This code is contributed by aashish1995


Javascript




<script>
// JavaScript code to verify Lemoine's Conjecture
// for any odd number >= 7
 
// Function to check if a number is
// prime or not
function isPrime(n)
{
    if (n < 2)
        return false;
         
    for (let i = 2; i <= Math.sqrt(n); i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}
 
// Representing n as p + (2 * q) to satisfy
// lemoine's conjecture
function lemoine(n)
{
    // Declaring a map to hold pairs (p, q)
    let pr = new Map();
     
    // Finding various values of p for each q
    // to satisfy n = p + (2 * q)
    for (let q = 1; q <= Math.floor(n / 2); q++)
    {
        let p = n - 2 * q;
         
        // After finding a pair that satisfies the
        // equation, check if both p and q are
        // prime or not
        if (isPrime(p) && isPrime(q))
         
            // If both p and q are prime, store
            // them in the map
            if(!pr.has(p)){
                pr.set(p, q);
            }
    }
     
    // Displaying all pairs (p, q) that satisfy
    // lemoine's conjecture for the number 'n'
    for (const [key, value] of pr)
        console.log(n, "=", key, " + (2 *", value, ")");
}
 
// Driver Function
let n = 39;
console.log(n, "can be expressed as ");
 
// Function calling
lemoine(n);
 
// This code is contributed by Gautam goel (gautamgoel962)
</script>


Output : 
 

39 can be expressed as :
39 = 5 + (2 * 17)
39 = 13 + (2 * 13)
39 = 17 + (2 * 11)
39 = 29 + (2 * 5)

Time Complexity: O(n*(sqrt(n)+log(n)))
Auxiliary Space: O(n)



Similar Reads

Ramanujan–Nagell Conjecture
The Ramanujan-Nagell equation is an equation between a number (say, x) which is squared and another number (say, z) such that z = [Tex]2^n - 7[/Tex]. Here, n can be any positive natural number which satisfies the equation. It is an example of an exponential Diophantine equation, which is an equation that can have only integral solutions with one of
1 min read
Legendre's Conjecture
It says that there is always one prime number between any two consecutive natural number's(n = 1, 2, 3, 4, 5, ...) square. This is called Legendre's Conjecture. Conjecture: A conjecture is a proposition or conclusion based upon incomplete information to which no proof has been found i.e it has not been proved or disproved. Mathematically, there is
5 min read
Triangle of numbers arising from Gilbreath's conjecture
The task is to find the triangle of numbers arising from Gilbreath's conjecture. Gilbreath's conjecture: It is observed that given a sequence of prime numbers, a sequence can be formed by the absolute difference between the ith and (i+1)th term of the given sequence and the given process can be repeated to form a triangle of numbers. This numbers w
11 min read
Maximum Sequence Length | Collatz Conjecture
Given an integer N. The task is to find the number in the range from 1 to N-1 which is having the maximum number of terms in its Collatz Sequence and the number of terms in the sequence.The collatz sequence of a number N is defined as: If N is Odd then change N to 3*N + 1.If N is Even then change N to N / 2. For example let us have a look at the se
6 min read
Goldbach's Weak Conjecture for Odd numbers
Given an odd number N, the task is to find if the number can be represented as the sum of 3 prime numbers.Examples: Input: N = 7 Output: Yes Explanation: 2 + 2 + 3 = 7 Input: N = 17 Output: Yes Explanation: 2 + 2 + 13 = 17 Approach: In number theory, Goldbach's weak conjecture, also known as the odd Goldbach conjecture, the ternary Goldbach problem
3 min read
Program to implement Collatz Conjecture
Given a positive integer n, the task is to find whether this number reaches 1 after performing the following two operations:- If n is even, then n = n/2.If n is odd, then n = 3*n + 1.Repeat the above steps, until it becomes 1.For example, for n = 12, we get the sequence 12, 6, 3, 10, 5, 16, 8, 4, 2, 1. Examples: Input : n = 4Output : YesInput : n =
7 min read
Program for Goldbach’s Conjecture (Two Primes with given Sum)
Goldbach's conjecture is one of the oldest and best-known unsolved problems in the number theory of mathematics. Every even integer greater than 2 can be expressed as the sum of two primes. Examples: Input : n = 44 Output : 3 + 41 (both are primes) Input : n = 56 Output : 3 + 53 (both are primes) Recommended: Please solve it on "PRACTICE" first, be
12 min read
three90RightbarBannerImg