bool is_prime (const vector<int>& primes, int num) { for (const auto& prime : primes) { if (num % prime == 0) { return false; } } return true; } vector<int32_t> get_primes (const int32_t& num) { vector<int32_t> primes; primes.push_back (2); int32_t vec_size = 1; for (int32_t i = 3; vec_size != num; i += 2) { if (is_prime (primes, i)) { primes.push_back (i); ++vec_size; } } return move (primes); }
时间: 2024-11-05 17:58:48