Queries on the sum of prime factor counts in a range | Python3 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
MAX = 100006 ; NEW_LINE count = [ 0 ] * MAX ; NEW_LINE def sieve ( ) : NEW_LINE INDENT i = 2 ; NEW_LINE while ( i * i <= MAX ) : NEW_LINE INDENT if ( count [ i ] == 0 ) : NEW_LINE INDENT for j in range ( 2 * i , MAX , i ) : NEW_LINE INDENT count [ j ] += 1 ; NEW_LINE DEDENT count [ i ] = 1 ; NEW_LINE DEDENT i += 1 ; NEW_LINE DEDENT DEDENT def query ( l , r ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( l , r + 1 ) : NEW_LINE INDENT sum += count [ i ] ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT sieve ( ) ; NEW_LINE print ( query ( 6 , 10 ) , query ( 1 , 5 ) ) ; NEW_LINE