forked from behappyyoung/javascriptsamplecodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck_Prime_Numbers.js
More file actions
34 lines (31 loc) · 806 Bytes
/
Copy pathCheck_Prime_Numbers.js
File metadata and controls
34 lines (31 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Created by youngsug on 5/16/2016.
*/
function primes(x)
{
var totalnum=[];
if(x<2) return totalnum;
if(x>=2){
totalnum.push(2);
}
var isPrime = function(n){
if(n<2) return false;
for(var i=0;i<totalnum.length; i++){
if( n % totalnum[i] === 0 ) return false;
}
return true;
};
for(var k=3;k<=x ; k=k+2){
if(isPrime(k)) totalnum.push(k);
}
return totalnum;
}
var primeArr = primes(100);
console.log(primeArr, primeArr.length);
console.log ( 'type number : ');
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) {
var primeArr = primes(input);
console.log(primeArr.length, ' : ', primeArr.toString() );
});