Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int countPrimes(int N) {
- int ans=0;
- vector < bool > is_prime(N , true);
- is_prime[0] = is_prime[1] = false;
- for(long long i = 2; i * i < N; i++)
- if(is_prime[i])
- for(long long j = i * i; j < N; j += i)
- is_prime[j] = false;
- for(int i = 2; i < N ; i++)
- if(is_prime[i])
- ans++;
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement