Lemoine's conjecture - named after Émile Lemoine - defines that every odd integer greater than 5 is represented as the sum of an odd prime number and an even semiprime. Basically, we get \(2n + 1 = p + 2q\) and where \(p\) and \(q\) are prime numbers, and \(n>2\).
Lemoine's conjecture |
Coding
The code from here is [1]:
namespace lemoine { class Program { public class pair { public int first, second; public pair(int first, int second) { this.first = first; this.second = second; } } 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 Dictionarylemoine(int n) { // Declaring a map to hold pairs (p, q) Dictionary pr = new Dictionary (); // Declaring an iterator for map // Dictionary ::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' return (pr); } static void Main(string[] args) { int n = 39; if (args.Length >0) n=Convert.ToInt32(args[0]); try { Console.Write(n + " can be expressed as " + "\n"); var pr = lemoine(n); foreach (KeyValuePair<int, pair> it in pr) Console.Write(n + " = " + it.Value.first + " + (2 * " + it.Value.second + ")\n"); } catch (Exception e) { Console.WriteLine("Error: {0}",e.Message); } } } }
References
[1] https://www.geeksforgeeks.org/lemoines-conjecture/