Numbers in range [ L , R ] such that the count of their divisors is both even and prime | PHP implementation of the approach ; stores whether the number is prime or not ; stores the count of prime numbers less than or equal to the index ; create the sieve ; Create a boolean array " prime [ 0 . . n ] " and initialize all the entries as true . A value in prime [ i ] will finally be false if ' i ' is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; stores the prefix sum of number of primes less than or equal to ' i ' ; create the sieve ; ' l ' and ' r ' are the lower and upper bounds of the range ; get the value of count ; display the count
< ? php $ MAX = 100000 ; $ prime = array_fill ( 0 , $ MAX + 1 , true ) ; $ sum = array_fill ( 0 , $ MAX + 1 , 0 ) ; function SieveOfEratosthenes ( ) { global $ MAX , $ sum , $ prime ; $ prime [ 1 ] = false ; for ( $ p = 2 ; $ p * $ p <= $ MAX ; $ p ++ ) { if ( $ prime [ $ p ] ) { for ( $ i = $ p * 2 ; $ i <= $ MAX ; $ i += $ p ) $ prime [ $ i ] = false ; } } for ( $ i = 1 ; $ i <= $ MAX ; $ i ++ ) { if ( $ prime [ $ i ] == true ) $ sum [ $ i ] = 1 ; $ sum [ $ i ] += $ sum [ $ i - 1 ] ; } } SieveOfEratosthenes ( ) ; $ l = 3 ; $ r = 9 ; $ c = ( $ sum [ $ r ] - $ sum [ $ l - 1 ] ) ; echo " Count : " ▁ . ▁ $ c ▁ . ▁ " " ? >