Lemoine 's Conjecture | Java 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 HashMap < Integer , Integer > :: iterator it ; it = pr . begin ( ) ; ; 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
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } 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 ; } static void lemoine ( int n ) { HashMap < Integer , pair > pr = new HashMap < > ( ) ; int i = 0 ; for ( int q = 1 ; q <= n / 2 ; q ++ ) { int p = n - 2 * q ; if ( isPrime ( p ) && isPrime ( q ) ) pr . put ( i , new pair ( p , q ) ) ; i ++ ; } for ( Map . Entry < Integer , pair > it : pr . entrySet ( ) ) System . out . print ( n + " ▁ = ▁ " + it . getValue ( ) . first + " ▁ + ▁ ( 2 ▁ * ▁ " + it . getValue ( ) . second + ")NEW_LINE"); } public static void main ( String [ ] args ) { int n = 39 ; System . out . print ( n + " ▁ can ▁ be ▁ expressed ▁ as ▁ " + "NEW_LINE"); lemoine ( n ) ; } }