标题: 刚写了一个关于素数的代码 [打印本页] 作者: 大地z灵 时间: 2015-10-18 10:15 标题: 刚写了一个关于素数的代码 public class SushuDemo2 {
public static void main(String[] args) {
Long x = 90000000000000L;
System.out.println(Long.MAX_VALUE);//9223372036854775807
long start = new Date().getTime();
while (x<Long.MAX_VALUE) {
boolean flag = true;
int sq = (int) Math.sqrt(x);
for (int y = 2; y <= sq; y++) {
if (x % y == 0) {
flag = false;
continue;
}
}
if(flag == true) {
System.out.println(x);
long end = new Date().getTime();
System.out.println(end-start);
}
x++;
}
}
}