Count of elements having Euler 's Totient value one less than itself | Python3 program for the above approach ; Seiev of Erotosthenes method to compute all primes ; If current number is marked prime then mark its multiple as non - prime ; Function to count the number of element satisfying the condition ; Compute the number of primes in count prime array ; Print the number of elements satisfying the condition ; Given array ; Size of the array ; Function call
prime = [ 0 ] * ( 1000001 ) NEW_LINE def seiveOfEratosthenes ( ) : NEW_LINE INDENT for i in range ( 2 , 1000001 ) : NEW_LINE INDENT prime [ i ] = 1 NEW_LINE DEDENT i = 2 NEW_LINE while ( i * i < 1000001 ) : NEW_LINE INDENT if ( prime [ i ] == 1 ) : NEW_LINE INDENT for j in range ( i * i , 1000001 , i ) : NEW_LINE INDENT prime [ j ] = 0 NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT DEDENT def CountElements ( arr , n , L , R ) : NEW_LINE INDENT seiveOfEratosthenes ( ) NEW_LINE countPrime = [ 0 ] * ( n + 1 ) NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT countPrime [ i ] = ( countPrime [ i - 1 ] + prime [ arr [ i - 1 ] ] ) NEW_LINE DEDENT print ( countPrime [ R ] - countPrime [ L - 1 ] ) NEW_LINE return NEW_LINE DEDENT arr = [ 2 , 4 , 5 , 8 ] NEW_LINE N = len ( arr ) NEW_LINE L = 1 NEW_LINE R = 3 NEW_LINE CountElements ( arr , N , L , R ) NEW_LINE