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