LeetCode—Count Primes
2015-07-20 15:31
281 查看
Description:
Count the number of prime numbers less than a non-negative number, n.
就是求小于非负整数n的质素的个数(质数:只能被自己和1整除的整数)。
Count the number of prime numbers less than a non-negative number, n.
就是求小于非负整数n的质素的个数(质数:只能被自己和1整除的整数)。
public int countPrimes(int n) { if(n==0) return 0; if(n==1) return 0; int count=0; boolean[] notPrime=new boolean ; for(int i=2;i<n;i++){ if(notPrime[i]==false) count++; for(int j=2;i*j<n;j++){ notPrime[i*j]=true; } } return count; }
相关文章推荐
- IOS:MD5加密
- php 数组转xml
- zoj 1586 QS Network
- 欢迎使用CSDN-markdown编辑器
- getApn has exception: No permission to write APN settings
- 让多个Fragment切换不实例化
- zoj 1586 QS Network
- 职场中的十大低级错误
- hdu 1814 Peaceful Commission(2-sat)
- 通过浏览器直接打开Android应用程序
- 【CF】222 Div.1 B Preparing for the Contest
- [转]关于GET和POST的区别
- Java学习从入门到精通Java Learning Path
- ACM_Floyd-Warshall (Floyd) 算法
- redis-cluster研究和使用
- C#简单总结
- Android Service 服务(二)—— BroadcastReceiver
- Android中播放本地SD卡中歌曲需要的添加的权限
- android的布局属性详解
- NYOJ737