计数质数
https://leetcode.cn/problems/count-primes/description/
class Solution { public: bool isPrime(int x) { for (int i = 2; i * i <= x; ++i) { if (x % i == 0) { return false; } } return true; } int countPrimes(int n) { int ans = 0; for (int i = 2; i < n; ++i) { ans += isPrime(i); } return ans; } };
浙公网安备 33010602011771号