<html><head>
<meta name="viewport" content="width=device-width">
<script>
var d=document;
var primes=[];
function Prime(){
for (var i=2; i<=2000000;i++){
if (this.check(i, primes)){
primes.push(i);
d.write(i+" ");
}
}
}
Prime.prototype.check=function(i, primes){
var isOdd=i%2;
var isPrime=true;
var n=2;
if(i==2 || isOdd){
var to=Math.floor(i/2);
if (primes.length>0){
for (var j=0;j<primes.length; j++){
n=primes[j];
if(n>to){
break;
}
if(i%n==0){
isPrime=false;
break;
}
}
}
for(;n<=to;n++){
if(i%n==0){
isPrime=false;
break;
}
}
} else {
isPrime=false;
}
return isPrime;
}
function main(){
var p=new Prime();
}
</script>
</head>
<body onload="main()">default</body>
</html>
Web Inspector:
23.51s