Nth Term of a Fibonacci Series of Primes formed by concatenating pairs of Primes in a given range | Stores at each index if it 's a prime or not ; Sieve of Eratosthenes to generate all possible primes ; If p is a prime ; Set all multiples of p as non - prime ; Function to generate the required Fibonacci Series ; Stores all primes between n1 and n2 ; Generate all primes between n1 and n2 ; Stores all concatenations of each pair of primes ; Generate all concatenations of each pair of primes ; Stores the primes out of the numbers generated above ; Store the unique primes ; Find the minimum ; Find the minimum ; Find N ; Print the N - th term of the Fibonacci Series ; Driver Code
prime = [ True for i in range ( 100001 ) ] NEW_LINE def SieveOfEratosthenes ( ) : NEW_LINE INDENT p = 2 NEW_LINE while ( p * p <= 100000 ) : NEW_LINE INDENT if ( prime [ p ] == True ) : NEW_LINE INDENT for i in range ( p * p , 100001 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT p += 1 NEW_LINE DEDENT DEDENT def fibonacciOfPrime ( n1 , n2 ) : NEW_LINE INDENT SieveOfEratosthenes ( ) NEW_LINE initial = [ ] NEW_LINE for i in range ( n1 , n2 ) : NEW_LINE INDENT if prime [ i ] : NEW_LINE INDENT initial . append ( i ) NEW_LINE DEDENT DEDENT now = [ ] NEW_LINE for a in initial : NEW_LINE INDENT for b in initial : NEW_LINE INDENT if a != b : NEW_LINE INDENT c = str ( a ) + str ( b ) NEW_LINE now . append ( int ( c ) ) NEW_LINE DEDENT DEDENT DEDENT current = [ ] NEW_LINE for x in now : NEW_LINE INDENT if prime [ x ] : NEW_LINE INDENT current . append ( x ) NEW_LINE DEDENT DEDENT current = set ( current ) NEW_LINE first = min ( current ) NEW_LINE second = max ( current ) NEW_LINE count = len ( current ) - 1 NEW_LINE curr = 1 NEW_LINE while curr < count : NEW_LINE INDENT c = first + second NEW_LINE first = second NEW_LINE second = c NEW_LINE curr += 1 NEW_LINE DEDENT print ( c ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x = 2 NEW_LINE y = 40 NEW_LINE fibonacciOfPrime ( x , y ) NEW_LINE DEDENT