public class Solution { public int countPrimes(int n) { boolean[] isDelArray = new boolean[n];
来源:互联网 发布:ubuntu 查看mysql 编辑:程序博客网 时间:2024/05/16 14:16
1.注意边界条件
public class Solution {public int countPrimes(int n) {boolean[] isDelArray = new boolean[n];if (n <= 2)return 0;isDelArray[2] = false;for (int i = 3; i < n; i++) {if (i % 2 == 0)isDelArray[i] = true;elseisDelArray[i] = false;}for (int i = 3; i < n; i += 2) {if (!isDelArray[i]) {if (i * i > n)break;for (int j = 2; i * j < n; j++) {isDelArray[i * j] = true;}}}int ans = 0;for (int i = 2; i < n; i++) {if (!isDelArray[i])ans++;}return ans;}}参考:
1.http://blog.csdn.net/lisonglisonglisong/article/details/45309651
阅读全文
0 0
- public class Solution { public int countPrimes(int n) { boolean[] isDelArray = new boolean[n];
- public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p== null
- 最大公约数和最小公倍数import java.util.Scanner; public class Main10 { public static int gcd(int m, int n) {
- public boolean hasPara
- public boolean createNewFile () 解释
- public boolean isMutable
- public boolean isMutable
- public boolean update
- 数组配对 给定N个整数,N为偶数,是否能找到N/2对,使得每对和能被K整除。注意:每个元素只能出现在一个配对中。public class num9 { public boolean checkP
- int *p= new int [n] 与 int *p =new int [n]() 差别
- java int 转boolean
- JAVA之设计方法boolean prime(int n),判断是否为素数,并抛出异常
- public final int readInt()
- int *n;int &n;int *&n
- public boolean isAdmin(String adminId,String adminPwd)
- new class[] = {int.class}
- java基础 复习boolean和Boolean,类似int和Integer
- new StringBuffer(int n)的陷阱
- Java8种排序算法学习
- Java数组、遍历数组
- Redis:存储对象的两种方式(序列化和json字符串)
- 用两个队列实现栈和用两个栈实现队列
- 51nod 1267 4个数和为0
- public class Solution { public int countPrimes(int n) { boolean[] isDelArray = new boolean[n];
- PowerDesigner中NAME和COMMENT的互相转换,需要执行语句
- 动/静态接收系统广播
- Mysql 表设计
- Socket的简单数据传递
- CreateProcessAsUser常用参数说明
- Dinic最大流(bzoj 2756: [SCOI2012]奇怪的游戏)
- opencv学习之数据结构与数据操作
- python Sublime Text3的使用基本配置操作&&SublimeREPL插件的安装及快捷键设置