// C++ program to print print all primes smaller than // n using segmented sieve #include using namespace std; #define ll long long vector primes; void simpleSieve(ll limit, vector &prime) { // Create a boolean array "mark[0..n-1]" and initialize // all entries of it as true. A value in mark[p] will // finally be false if 'p' is Not a prime, else true. bool mark[limit+1]; memset(mark, true, sizeof(mark)); for (ll p=2; p*p prime; simpleSieve(limit, prime); // Divide the range [0..n-1] in different segments // We have chosen segment size as sqrt(n). int low = limit; int high = 2*limit; // While all segments of range [0..n-1] are not processed, // process one segment at a time while (low < n) { // To mark primes in current range. A value in mark[i] // will finally be false if 'i-low' is Not a prime, // else true. bool mark[limit+1]; memset(mark, true, sizeof(mark)); // Use the found primes by simpleSieve() to find // primes in current range for (ll i = 0; i < prime.size(); i++) { // Find the minimum number in [low..high] that is // a multiple of prime[i] (divisible by prime[i]) // For example, if low is 31 and prime[i] is 3, // we start with 33. int loLim = floor(low/prime[i]) * prime[i]; if (loLim < low) loLim += prime[i]; /* Mark multiples of prime[i] in [low..high]: We are marking j - low for j, i.e. each number in range [low, high] is mapped to [0, high-low] so if range is [50, 100] marking 50 corresponds to marking 0, marking 51 corresponds to 1 and so on. In this way we need to allocate space only for range */ for (ll j=loLim; j= n) high = n; } } // Driver program to test above function int main() { int n = 1000005,x,i,j; segmentedSieve(n); cin>>x; vector a(x); for(i=0;i>a[i]; ll res=0; for(i=0;i1&&num%primes[j]==0){ res+=num/primes[j]; num=num/primes[j]; //cout<1) res+=1; //cout<