Lemoine 's Conjecture | Python 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 ) ; 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 Code ; Function calling
from math import sqrt NEW_LINE def isPrime ( n : int ) -> bool : NEW_LINE INDENT if n < 2 : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 2 , int ( sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def lemoine ( n : int ) -> None : NEW_LINE INDENT pr = dict ( ) NEW_LINE for q in range ( 1 , n // 2 + 1 ) : NEW_LINE INDENT p = n - 2 * q NEW_LINE if isPrime ( p ) and isPrime ( q ) : NEW_LINE INDENT if p not in pr : NEW_LINE INDENT pr [ p ] = q NEW_LINE DEDENT DEDENT DEDENT DEDENT ' NEW_LINE INDENT for it in pr : NEW_LINE INDENT print ( " % d ▁ = ▁ % d ▁ + ▁ ( 2 ▁ * ▁ % d ) " % ( n , it , pr [ it ] ) ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 39 NEW_LINE print ( n , " can ▁ be ▁ expressed ▁ as ▁ " ) NEW_LINE lemoine ( n ) NEW_LINE DEDENT