<html>
<head>
<meta charset="utf-8">
<title>素數算法</title>
</head>
<body>
<p>素數算法</p>
<br>
<script >
var arr=new Array();
var n=parseInt(prompt(" 請輸入要列出素數在多少整數范圍之內:", " "));
//1
for (i=0; i<=n; i++){
arr[i]=0;
}
//
for (k=2; k<=n; k++){
j=k;
while(j+k<=n){
j=j+k;
if(arr[j]==0){
arr[j]=1;
}
}
}
//3
var arr_prime=new Array();
for( i=2; i<=n; i++){
if(arr[i]==0){
arr_prime.push(i);
}
}
// 4 view
for (i=0; i<arr_prime.length; i++){
if((i+1)%13 ){
document.write(arr_prime[i]+"; ");
}
else{
document.write(arr_prime[i]+ "; <br>");
}
}
</script>
</body>
</html>