Count Primes
Total Accepted: 43534 Total Submissions: 196140 Difficulty: Easy
Description:
Count the number of prime numbers less than a non-negative number, n.
class Solution { public: int countPrimes(int n) { vector<bool> map(n,false); int count = n<=2 ? 0:1 ; for (int i=3; i<n; i+=2) { if (map[i]) continue; count++; for(int j=3*i; j < n; j += 2*i){ map[j] = true; } } return count; } };
写者:zengzy
出处: http://www.cnblogs.com/zengzy
标题有【转】字样的文章从别的地方转过来的,否则为个人学习笔记