Queries on the sum of prime factor counts in a range | C ++ 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 . ; Driven Program
#include <bits/stdc++.h> NEW_LINE #define MAX  1000006 NEW_LINE using namespace std ; void sieve ( int count [ ] ) { for ( int i = 2 ; i * i <= MAX ; i ++ ) { if ( count [ i ] == 0 ) { for ( int j = 2 * i ; j < MAX ; j += i ) count [ j ] ++ ; count [ i ] = 1 ; } } } int query ( int count [ ] , int l , int r ) { int sum = 0 ; for ( int i = l ; i <= r ; i ++ ) sum += count [ i ] ; return sum ; } int main ( ) { int count [ MAX ] ; memset ( count , 0 , sizeof count ) ; sieve ( count ) ; cout << query ( count , 6 , 10 ) << endl << query ( count , 1 , 5 ) ; return 0 ; }