Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

class Solution { public: int countPrimes(int n) { vector<bool> nums(n,true); int i,cnt=0; nums[0]=false;nums[1]=false; for(i=2;i<n;i++) { if(nums[i]==true) { cnt++; for(int j=i*i;j<n;j+=i) { nums[j]=false; } } } return cnt; } };

@just95 i*i is an overflow

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.