Queries on the sum of prime factor counts in a range | PHP program to find sum prime factors in given range . ; using sieve method to evaluating the prime factor of numbers ; if i is prime ; setting number of prime factor of a prime number . ; Returns sum of counts of prime factors in range from l to r . This function mainly uses count [ ] which is filled by Sieve ( ) ; finding the sum of number of prime factor of numbers in a range . ; Driver Code
< ? php $ MAX = 100006 ; function sieve ( & $ count ) { global $ MAX ; for ( $ i = 2 ; $ i * $ i <= $ MAX ; $ i ++ ) { if ( $ count [ $ i ] == 0 ) { for ( $ j = 2 * $ i ; $ j < $ MAX ; $ j += $ i ) $ count [ $ j ] ++ ; $ count [ $ i ] = 1 ; } } } function query ( $ count , $ l , $ r ) { $ sum = 0 ; for ( $ i = $ l ; $ i <= $ r ; $ i ++ ) $ sum += $ count [ $ i ] ; return $ sum ; } $ count = array_fill ( 0 , $ MAX , 0 ) ; sieve ( $ count ) ; echo query ( $ count , 6 , 10 ) . " " . query ( $ count , 1 , 5 ) ; ? >