Program to find sum of prime numbers between 1 and 10^7

std::vector<uint> primes = {2,3,5};
bool check_prime(uint x){    
    bool result = true;
    for(auto i: primes){
        if(i*i>x){
            break;
        }
        if(x%i==0){
            result = false;
            break;
        }
    }
    if(result){
        primes.push_back(x);
    }
    return result;
}

void get_primes(){
    for(uint x =6; i<N; i++){
        check_prime(x);
    }
}

uint get_sum(){
    return std::accumulate(primes.begin(), primes.end(), 0, std::plus);
}

Leave a Comment