Project Euler #10: Summation of primes

  • + 0 comments

    include

    include

    include

    using namespace std; bool isprime(long number){ if((number != 2 && number != 3 && number != 5) && (number % 2 == 0 || number % 3 == 0 || number % 5==0))

    return false;
    
    for(long i =2; i*i <= number; i++){
        if(number % i == 0)
        return false;
    }
    return true;
    

    }

    int main(){ vector primes; for(long i = 2; i<1000000; i++){ if (isprime(i)) primes.push_back(i); }

    int t;
    cin >> t;
    for(int a0 = 0; a0 < t; a0++){
        int n;
        cin >> n;
        long sum = 0;
    
        for(long num : primes){
            if(num >n)
            break;
            sum += num;
        }
        cout << sum << endl;
    }
    
    return 0;
    

    }