Count Primes
2015-06-08 22:11
375 查看
Count the number of prime numbers less than a non-negative number, n.
class Solution { public: int countPrimes(int n) { if(n <= 2) return 0; int res = 1; for(int i = 3;i < n; i+=2){ int bound = sqrt(i),j; for(j = 3; j <= bound; j+=2) { if(i%j == 0) break; } if(j > bound) ++res; } return res; } };
相关文章推荐
- c++ --> 友元函数
- 第一题
- MixtureComponent API
- Yii2的YiiBase自动加载类、引用文件(autoload)
- Qemu对x86静态内存布局的模拟
- Loader API
- s5pv210 linux3.8.3内核移植之三:简单根文件系统制作
- extern用法详解(转)
- 用callgraph生成的两张函数调用关系图
- Java输入输出流总结
- mysql的3306端口拒绝访问导致hive无法正常启动
- NOIP 2014 D1T1 -生活大爆炸版石头剪刀布
- [NetTopologySuite](2)任意多边形求交
- 搭建heartbeat运行后发现nginx及VIP不能正常启动
- Codeforces Round #306 (Div. 2)B. Preparing Olympiad--状态压缩
- Fire and Forget模式
- PMP考试试题及答案解析
- PHP设计模式——迭代器模式
- Jmeter- Building a Web test plan(1)
- openssl中dh算法Demo